Linux Commands
Linux Commands
• - - help
• man
Navigation Commands
Linux Command Description
pwd “Print Working Directory”. Shows the current location in the
directory tree.
cd “Change Directory”. When typed all by itself, it returns you
to your home directory.
cd directory Change into the specified directory name.
Example: cd /usr/src/linux
cd ~ “~” is an alias for your home directory. It can be used as a
shortcut to your “home”, or other directories relative to your
home.
Continue...
Linux Command Description
cd .. Move up one directory. For example, if you are in
/home/vic and you type “cd ..”, you will end up in
/home.
cd - Return to previous directory. An easy way to get back to your
previous location!
ls List all files in the current directory, in column format.
ls directory List the files in the specified directory.
Example: ls /var/log
ls -l List files in “long” format, one file per line. This also shows
you additional info about the file, such as ownership,
permissions, date, and size.
Continue...
Linux Command Description
ls -a List all files, including “hidden” files. Hidden files are those
files that begin with a “.”, e.g. The
.bash_history file in your home directory.
ls -ld A “long” list of “directory”, but instead of showing the
directory directory contents, show the directory’s detailed information.
For example, compare the output of the following two
commands:
ls -l /usr/bin
ls -ld /usr/bin
ls List all files whose names begin with the letter “d”
/usr/bin/d* in the /usr/bin directory.
Working With Files and Directories
Linux Command Description
which Shows the full path of shell commands found in your path. For
example, if you want to know exactly where the “grep”
command is located on the filesystem, you can type “which
grep”. The output should be something like: /bin/grep
whereis Locates the program, source code, and manual page for a
command (if all information is available). For example, to find
out where “ls” and its man page are, type: “whereis ls”
The output will look something like:
ls: /bin/ls /usr/share/man/man1/ls.1.gz
Continue...
Linux Command Description
echo Display text on the screen. Mostly useful when writing shell
scripts. For example: echo “Hello World”
more Display a file, or program output one page at a time.
Examples: more mp3files.txt
ls -la | more
less An improved replacement for the “more” command. Allows
you to scroll backwards as well as forwards.
Continue...
Linux Command Description
> Redirect output of a command into a new file. If the file already
exists, over-write it.
Example: ls > myfiles.txt
>> Redirect the output of a command onto the end of an existing file.
Example: echo “Mary 555-1234” >>
phonenumbers.txt
< Redirect a file as input to a program.
Example: more < phonenumbers.txt
Continue...
Character Description
Up/Down Arrow Scroll through your most recent commands. You can scroll
Keys back to an old command, hit ENTER, and execute the
command without having to re-type it.
“history” Show your complete command history.
command
TAB Completion If you type a partial command or filename that the shell
recognizes, you can have it automatically completed for you if
you press the TAB key. Try typing the first few characters of
your favourite Linux command, then hit TAB a couple of
times to see what happens.
Continue...
Shortcut Description
Complete recent Try this: Type “!” followed by the first couple of letters of a recent
commands with “!” command and press ENTER! For example, type:
find /usr/bin -type f -name m\*
...and now type:
!fi
Search your Press CTRL-R and then type any portion of a recent command. It
command history will search the commands for you, and once you find the command
with CTRL-R you want, just press ENTER.
Scrolling the screen Scroll back and forward through your terminal.
with Shift-
PageUp and Page
Down