The UNIX/BASH Command Line

  1. The command line is offered by a program called your 'shell'.
  2. Your shell by default is called 'bash', the Bourne Again Shell.
  3. Bash could be replaced by another program if you wanted.
  4. Standard commands are ...

 
Command Example Works with
STDIN/OUT
Function
ls ls /tmp Both List files (like dir)
ls -l ls -l /tmp Both List files long format
cp cp src dest None Copies files
mv mv oldname newname None Moves or changes the name of a file.
Cannot move a directory across between filesystems.
rm rm oldfile None Deletes a file
rm -rf rm -rf / None Deletes an entire subtree.
Can wipe out your whole hard drive!!
df df  Out Shows free disk space.
Shows all filesystems mounted
du du /tmp Out Shows space used by a subtree
Requires permissions to read the subtree.
Can be slow on big subtrees.
cd cd None Change current dir to home dir.
cd cd /tmp None Change current dir to given dir.
chmod chmod a+rwx filename None Change permissions
chmod -R chmod -R go-rwx . None Change permissions for a whole subtree.
chown chown randy /home/randy None Change owner.
You must be root to use this command.  Being the owner of the file is not enough!
chown -R chown -R randy /home/randy None Changes a whole subtree.
less less /tmp/README In Shows file to the screen.
grep  grep BUGS /tmp/README Both Shows lines containing the pattern to the screen.
grep -v grep -v BUGS /tmp/README Both Shows lines NOT containing the pattern to the screen.
cat cat file1 file2 Both Concatenates the files.
whoami whoami Out Tells your current username.
su su randy None Changes your current username.
requires a password for everyone except root.
time time du /tmp Out Tells how long the command takes to run.
sort sort /tmp/file-list Both Prints files in alphabetic order. (-r reverses order).
sort -n sort -n /tmp/list-of-numbers Both Prints files in number order. (-r reverses order).
head  head -20 /tmp/list Both Prints only the first twenty lines.
tail tail -20 /tmp/list Both Prints the last twenty lines.
gcc gcc fred.c -o fred None Compiles the file fred.c into the executable fred
g++ g++ fred.cc -o fred None Compiles the file fred.cc into the executable fred
./command ./fred None Runs the program you just compiled.
pico pico fred.cc None Edit the program source code fred

Commands can be combined.

To run commands consecutively, try separating them with a semi-colon.
    ls; df; du

To run commands simultaneously, separate them with a '&'.
    rm -rf /tmp & rm -rf /junk

To run commands and not wait for them to finish, end the command line with a '&'.
    rm -rf /junk &

To put the output of one command into the input of another, separate them with a pipe.
    ls | sort

To place the output of a command into a file, use a greater than symbol.
    ls > file-list

To have a command read from a file, use a less-than symbol.
    sort < file-list