| Version 19 (modified by , 13 years ago) ( diff ) |
|---|
Linux Shell Scripting Tutorial: A Beginner's handbook
You can do a lot of shell scripting type things in python with the os module: http://docs.python.org/library/os.html
To sort everything in a directory by size in human readable format (e.g. 8G, 1M, 12K)
$ du | sort -n | cut -f2- | xargs du -hs
To set the modified date to today for everything in a directory and all its subdirectories do
$ find . -exec touch {} \;
To get a list of all files in a directory (one per line) with their paths do
$ find . -type f -print
To remove files that have the string "foo" in them that are distributed throughout various subdirectories do:
$ find . -name '*foo*' | xargs rm
To use the output of one command as the input of another use ` which is the accent key on the upper left corner of the keyboard. For example, to display in ds9 the fits files whose names are listed one per line in a text file named listoffits.lis do:
$ ds9
`less listoffits.lis`
I always forget how to do this:
To tar and compress an entire directory do:
$ tar -zcvf foobar.tar.gz /home/foobar
where /home/foobar is the directory you want to archive.
To untar and uncompress said directory do:
$ tar -zxvf foobar.tar.gz
The v is optional.
