Basic Linux Commands
This
list comes courtesy of Mark Rais, our senior editor.
NOTE:
All of these commands should work from your command
prompt (regardless which shell you're using). Just in case some
folks were not aware, you MUST press enter to invoke the command
and the EX: stands for example and is not part of the command.
Commands are denoted in courier type
font. And of course, if they don't work or help you, we
appologize!
Command | Summary Use |
Use cd to change directories | Type cd
followed by the name of a directory to access that directory. Keep in mind that you are always in a directory and allowed access to any directories hierarchically above or below. Ex: cd games If the directory games is not located hierarchically below the current directory, then the complete path must be written out. Ex: cd /usr/games To move up one directory, use the shortcut command. Ex: cd .. |
Use mkdir
to create new directory |
Use mkdir
to make/create a brand new directory Type mkdir followed by the name of a directory. Ex: mkdir testdir |
Use rmdir to remove an existing directory | Use rmdir to remove an existing
directory (assuming you have permissions set to allow this). Type rmdir followed by a directory's name to remove it. Ex: rmdir testdir You CAN'T remove a directory that contains files with this command. A more useful command is rm -r that removes directories and files within the directories. You can read more about this in Commands for Beginning Admins The rmdir command is used mostly to remove empty directories. If you have a desire to use this command then you'll need to delete or move the files before attempting to remove a full directory. |
Use ls to list files and directories | Type ls
to see a list of the files and directories located in the current
directory. If you’re in the directory named games and you
type ls, a list will
appear that contains files in the games directory and sub-directories
in the games directory. Examples: ls Mail ls /usr/bin Type ls -alt to see a list of all files (including .rc files) and all directories located in the current directory. The listing will include detailed, often useful information. Examples: ls -alt ls -alt /usr/bin If the screen flies by and you miss seeing a number of files, try using the |more at the end like: ls -alt |more * In Bash (Linux shell) often the abbreviated command L is
available. To get a verbose listing of files and directories you could
therefore simply type: l |
Use man to pull up information about a Linux command | Type man
followed by a command to get detailed information about how to use the
command. Ex: man ls Type man -k followed by a word to list all of the commands and descriptions that contain the word you specified. Ex: man -k finger |
Use more to read the contents of a file | Type more
followed by the name of a text file to read the file’s contents. Why do
we exmphasize using this on a "text" file? Because most other types of
files will look like garbage! Ex: more testfile.txt |
cp | Type cp
followed by the name of an existing file and the name of the new file. Ex: cp newfile newerfile To copy a file to a different directory (without changing th e file’s name), specify the directory instead of the new filename. Ex: cp newfile testdir To copy a file to a different directory and create a new file name, you need to specify a directory/a new file name. Ex: cp newfile testdir/newerfile cp newfile ../newerfile The .. represents one directory up in the hierarchy. |
Use pwd to list the name of your current directory | Type pwd
and hit enter. You'll see the full name of the
directory you are currently in. This is your directory path and is very
handy. This is especially handy when you forget which directory you’ve
changed to and are trying to run other commands. |
mv
|
Type mv
followed by the current name of a file and the new name of the file. Ex: mv oldfile newfile Type mv followed by the name of a file and the new directory where you'd like to place the file. Ex: mv newfile testdir This moves the file named newfile to an existing directory named testdir. Be certain you’re specifying a directory name or the mv command alters the name of the file instead of moving it. |
Use rm to remove the file | Type rm followed by the name of a file to
remove the file. Ex: rm newfile Use the wildcard character to remove several files at once. Ex: rm n* This command removes all files beginning with n. Type rm -i followed by a filename if you’d like to be prompted before the file is actually removed. Ex: rm -i newfile rm -i n* By using this option, you have a chance to verify the removal of each file. The -i option is very handy when removing a number of files using the wildcard character *. |
Want more? Try Basic Linux Commands. Perhaps you're ready for our Commands for Guru Wanna-bees or review the Beginner commands for Server Administration.