Most Popular

1500 questions
79
votes
8 answers

mv: Move file only if destination does not exist

Can I use mv file1 file2 in a way that it only moves file1 to file2 if file2 doesn't exist? I've tried yes n | mv -i file1 file2 (this lets mv ask if file2 should be overridden and automatically answer no) but besides abusing -i it also doesn't…
79
votes
8 answers

How to rename multiple files using find

I want to rename multiple files (file1 ... fileN to file1_renamed ... fileN_renamed) using find command: find . -type f -name 'file*' -exec mv filename='{}' $(basename $filename)_renamed ';' But getting this error: mv: cannot stat…
user164014
  • 893
  • 1
  • 6
  • 6
79
votes
6 answers

How to create a TCP listener?

Introduction: I have created a bash function that is able to check whether a port is available and increments it by 1 if false until a certain maximum port number. E.g., if port 500 is unavailable then the availability of 501 will be checked until…
030
  • 1,527
  • 2
  • 17
  • 33
79
votes
15 answers

How to color diff output?

I wanted to format the Unix files conditionally, I am currently working on diff command and wanted to know if it is possible to format the text of the diff command output. Example: Matched values should be displayed in green. Unmatched values…
Aman
  • 1,151
  • 2
  • 11
  • 17
79
votes
9 answers

Does compression option -z with rsync speed up backup

In rsync, --compress or -z will compress file data during the transfer. If I understand correctly, it compresses files before transfer and then decompress them after transfer. Does the time reduced during transfer due to compression outweight the…
Tim
  • 98,580
  • 191
  • 570
  • 977
79
votes
4 answers

Write Python stdout to file immediately

When trying to write the stdout from a Python script to a text file (python script.py > log), the text file is created when the command is started, but the actual content isn't written until the Python script finishes. For example: script.py: import…
Bart
  • 890
  • 1
  • 7
  • 9
79
votes
9 answers

Why do we need to mount on Linux?

I understand what mounting is in Linux, and I understand device files. However I do not understand WHY we need to mount. For example, as explained in the accepted answer of this question, using this command: mount /dev/cdrom /media/cdrom we are…
Greeso
  • 893
  • 1
  • 7
  • 8
79
votes
6 answers

Get path of current script when executed through a symlink

I have a utility consisting of a couple of directories with some bash scripts and supporting files that will be deployed to several machines, possibly in a different directory on each machine. The scripts need to be able to reference paths relative…
Mike Deck
  • 1,383
  • 3
  • 12
  • 17
79
votes
9 answers
79
votes
6 answers

What is a better way to deal with server disconnects of sshfs mounts?

I have several directories mounted through sshfs. I sometimes get disconnects from the server (not configurable by me). I usually mount the directories like this sshfs [email protected]:/home/user /mnt/example When a server disconnects, the…
Sebastian
  • 8,677
  • 4
  • 39
  • 49
79
votes
3 answers

How do I find out if my wireless card supports 5 GHz?

I have the 03:00.0 Network controller: Intel Corporation Centrino Wireless-N 2200 (rev c4) How do I find out if that card/driver support 5 GHz?
Evan Carroll
  • 28,578
  • 45
  • 164
  • 290
79
votes
2 answers

Will Linux start killing my processes without asking me if memory gets short?

I was running a shell script with commands to run several memory-intensive programs (2-5 GB) back-to-back. When I went back to check on the progress of my script I was surprised to discover that some of my processes were Killed, as my terminal…
NeutronStar
  • 1,611
  • 4
  • 17
  • 19
79
votes
6 answers

protocol version mismatch (client 8, server 6) when trying to upgrade

I'm trying to upgrade to a newer version (that has a bug fix) than my current 1.6. I am on Ubuntu and recently upgraded to Ubuntu 13.04. Ideally I want to use tmux version 1.8 or even 1.9. I've downloaded newer versions but can't get them working. I…
Michael Durrant
  • 41,213
  • 69
  • 165
  • 232
79
votes
1 answer

Single command to login to SSH and run program?

Is there a way to structure a single command to login via SSH to a remote server and run a program on the remote login shell? In the OpenSSH manual, it reads "If command is specified, it is executed on the remote host instead of a login shell." So,…
user981178
  • 1,017
  • 1
  • 7
  • 10
79
votes
13 answers

How to randomly sample a subset of a file

Is there any Linux command one can use to sample subset of a file? For instance, a file contains one million lines, and we want to randomly sample only one thousand lines from that file. For random I mean that every line gets the same probability…
clwen
  • 923
  • 1
  • 6
  • 8