The Archives
-
11.27.09Ignoring an aliasSometimes I want to ignore an alias. That might seem to make no sense because one of the reasons (the reason?) to use an alias (like ls='ls --color') is creating shortcuts. But, in some cases I need to use the real command, with its real output. In my case, it is because I share the same username with other people on some systems (yes, it is pretty awful, but that is another issue). To do this, precede the command with a backslash: '\'. For example: $ \ls Update: As loood has said in the comments, typing the command in quotes has the same ...
-
11.25.09Comparing directories in local or remote hostsI frequently need to compare two directories (with similar structures) to find different or new files. When I have to compare them locally, I use the diff command. $ ls test* test: file1 file2 file3 file4 file5 test.new: file1 file2 file3 file4 file5 file6 $ diff -qr test test.new Files test/file2 and test.new/file2 differ Files test/file4 and test.new/file4 differ Only in test.new: file6 The -q option tells diff to tell only whether the files differ and the -r option is for recursively comparing inside subdirectories. A more complicated problem arises when the comparation has to be done remotely, that is one of the directories is in another host (Samba, NFS, etc ...
-
05.14.09Split a fileSometimes you need split a file. For example, to send them attached to an email. For this, you can use the split command. $ split -b 1m big_file file_part_ In the example, the big_file size is 10MB, the -b option split the file in 1MB pieces, and the file_part_ is the name given to the different parts. $ ls file_part_* file_part_aa file_part_ac file_part_ae file_part_ag file_part_ai file_part_ab file_part_ad file_part_af file_part_ah file_part_aj All the files are 1MB long. For joining all the parts you can ...
-
02.10.09Some xargsRafacas has already mentioned it, but xargs is sometimes much more useful than what it looks like. Two examples come to mind: Way too many files for rm or ls. It may well happen that a script has generated more than 10000 files in the same directory (it was your friend, not you, I know). If you try and rm * in there, you will be in trouble. Ditto if you simply want to count them with ls | wc -l. However, the following works: $ find . -type f -print0 | xargs -0 ls | wc -l (or rm instead of ...
-
09.17.08Time$ time for i in `ls` ; do cat $i ; done Shows the 'real', 'user' and 'sys' time invested in the task.
-
08.28.08Listing files ordered by date$ ls -lt Lists files ordered by date starting at the newest one.