Basic shell commands


When you open a terminal window, or login from another machine, you will almost always land in your home directory.
Much of Linux is navigating aroung the directory tree. To get started you will probably build your own tree for data analysis, creating directories and subdrietories for different projects, datasets, reduction runs etc.

Useful things to know:
(1) You can autocomplete commands and paths/filenames using Tab on the keyboard.
(2) The wildcard character is * to match multiple characters, and ? to match a single character. You can find exanmples below.
(3) You can paste into the terminal window or any editor by highlighting the text you want and clicking the right mouse button to paste. To copy & paste from a web browser or non-Linux file format (e.g. pdf) you'll have to do the proper copy first.

Find out what directory you are in
pwd
Naviagte to you the disk space you have been assigned
cd /reduction/myname
List what is in the current directory (-l for extra info/-h for readable filesizes)
ls -lh
List all files including normally hidden system ones
ls -a
List only files ending in .log
ls *.log
List all SMA files from the month of November
ls /sma/data/*/mir_data*/??11*
List only flux and baseline SMA files from the month of November
ls /sma/data/{flux,baseline}/mir_data*/??11*
Make a new directory there called project1
mkdir project1
Move into that directory
cd project1
Move back up the tree out of the data directory
cd ..
Move back up 2 levels
cd ../..
You can always shortcut to your home directory by doing cd on its own
cd
Rename file1 to file2
mv file1 file2
Make a copy of file1 called file1.bak
cp file1 file1.bak
Move file1 into the proejct1 directory
mv file1 project1
Remove a file (warning - this is very permenant!)
rm file1
Remove a directory
rm -r data
Print a text file to the screen
cat file1
Print a text file to the screen so it is scrollable
less file1        (q to exit out of less)
or
more file1
Check which machine you are on
hostname
Log on to a different machine on the RTDC network
ssh rtdc10
Check what processes are running
top        (q to exit out of top)
List previous commands you've used
history
Look up the manual entry for the mkdir command
man mkdir
Change your password (on the server)
yppasswd
Check which shell you are using (default is tcsh)
echo $0
Switch to a bash shell
bash
Print Hello in the terminal window
echo Hello
Print Hello into a file
echo Hello > greeting.txt
Redirect the output of a command (ls here) to a file
ls *txt > list.txt
Append an existing file with the output of a command
ls project1/*log >> list.txt
View a png file
display file.png
View a pdf file
evince file.pdf
Search for the phrase 2.0 Jy in all files in the current directory
grep -s '2.0 Jy' *
Tar compress a file or directory. Great for directories as it becomes a single file.
tar -cvf backup.tar directory
Untar a tar file
tar -xvf backup.tar