bembry.org
Home / Technology / Linux

Bash Commands

BASH is the command line interface used most commonly with Linux systems. This list is a brief cheat sheet containing some of the most common commands. Although Linux now has lots of graphical interfaces available, when you are connecting to computer using telnet, you really need to know bash.

O'reilly Books has an Alphabetical List of Linux Commands available online that is a lot more extensive than this. Essentials

  • cd -- Change to a different directory.
    cd /home/user1
  • cp -- Copy a file.
    cp file newfile
  • exit -- Exit. This can be used to exit the "su" mode, or to logout of your current session.
  • find-- Finds files according to parameters you give. Use -name to search by name and -size to search by size.
    find -name 'filename*'
  • locate-- Similar to find, but faster. Uses an internal dbase, instead of actively searching. Some systems have replaed locate with slocate.
    locate filename
  • ls -- Lists the files in a directory. Uses -a (shows hidden files) and -l (lists file info).
    ls -al /home/user
  • man-- Open the manual on a given command or program.
    man strings
  • mkdir-- Makes a new directory.
    mkdir /home/user1/newdirectory
  • mv-- Moves a file from one place to another. Also good for renaming a file.
    mv file /home/user1/file
  • rm-- Remove a file
    rm badfile
  • rmdir-- Remove a directory
    rmdir /home/user1/directory
  • su -- Log in as a subsitute user. If you are logged in as a low-priviledge user and need to run some commands as the root user, use "su" to change to the root user, or any other user for that matter.
    su root
  • vi -- Start the VI text editor program. May also be used to open a text file for viewing / editing in VI.
    vi textfile.txt
  • --help -- Following any command with "--help" will usually bring up a very short summary of what the command does and some common arguments that can be passed to it.
    rmdir --help
  • > -- Redirects the output of a given command. This is handy for creating a text file that has a list of all the files in a directory.
    ls > dir_list.txt
  • [TAB] -- If you have a long file name or directory name to type in, you can simply start typing the name and press the [TAB] button. The system will try to automatically complete the file name for you, or give you a choice of which file names match what you have typed so far. This only works if the file or directory name already exists on the system.
Extras
  • bc-- Starts a calculator on the command line. Note: Type "quit" to exit the calculator
  • cal-- Brings up a calendar of the month and date given
    cal 11 2000
  • cat -- Concatenates files. Used to pipe multiple text files into a single file.
    cat file1 file2 file3 > newfile
  • clear--Clears all the text from the screen
  • du -- Displays the disk usage of a current directory. Use -s for overall summary only.
    du /home/bembry
  • df-- Amount of free disk space available on system in kilobytes (usually). Also shows partition info.
  • free -- Displays amount of free RAM, both physical and virtual.
  • file -- Identifies the type of data contained in a file.
    file picture.xcf
  • more -- Displays file contents one screen at a time. Useful as a pipe redirect.
    more reallylongfile
    ls /bin | more
  • sort -- Prints out a file with lines sorted alphabetically. Uses -r (reverse), -u (eliminate duplicates), and -b (ignore leading whitespace). Probably another good one to redirect.
    sort phonebook.file
  • strings -- Prints out a binary file, removing any unreadable characters.
    strings filename
  • whoami -- Displays your current login name.
Restricted access