Professional Documents
Culture Documents
Basic Linux Commands PDF
Basic Linux Commands PDF
Directory Commands
pwd
cd
cd /dir1/subdir
cd subdir
Change working directory using relative paths (does not start with /)
cd ..
rmdir dirname
mkdir dirname
rmdir r dirname
File Commands
ls
ls l or ll
List content of the current directory and include sizes, dates, and other information
ls al
ls | more
List content of the current directory and pause when page is full
ls a
Notes:
- When specifying a directory as the target in the following commands, you need to use the
trailing slash, or else the command will treat dir_name as a file name.
- The -i option is not critical to the following commands but it provides an interactive "are you
sure?" prior to execution.
cp -i old_file new_file
cp p old_file new_file
cp I filename dir_name/
rm -i filename
mv old_name new_name
mv filename new_dir_name/
file filename
more filename
less filename
head filename
tail filename
tail f filename
Old School UNIX command. List the contents of a file, one page at
a time (ascii files only). more is also used as a switch to show
scrolling data one page at a time, such as: ls | more.
Like tail but continually updates the last 10 lines of the file as they
change or are updated. CTRL-c to exit. Useful for monitoring active
log files.
Wildcards are special characters that allow you to search for file names. There are two wildcards
available with LINUX:
grep is useful in searching for specific strings in file names or file contents.
Examples:
grep rpg /etc/hosts
ls /etc | grep host*
The first far left column in the illustration shows the type of file. For example, Desktop is a directory,
shown by the letter d. All others (with the -) are regular files.
The next 9 columns show the file permissions. 3 each for owner, group and others from left to
right.
Examples:
install.log looks like -rw-r--r-- First of all, it is NOT a directory (it has a dash in the first position).
The permissions are: rw- for owner. r-- for group and r-- for others. A dash - indicates the
permission is not set.
Desktop IS a directory and has permissions of: rwx for owner, r-x for group and r-x for others.
Skip over a column or two, and you will see the owner name and group name associated with that
file or directory. In this case, root is the owner of everything in this directory and only users in the group
root have access to these files.
chmod g +x filename
groupname group.
Process Commands
ps -ef
List the status of current process (or running programs) and its process
ps -fu user_id
identification (PID):
pstree
kill -9 PID
kill PID
NOTE: Use this command very carefully! It can have a drastic impact on your system. The kill PID
top
Miscellaneous Commands
su {password}
su - {password}
Become the Super User (root). (Some also call it Switch User)
Become the Super User (root) and assume roots environment (paths,
home directory, etc)
whoami
who r
exit
df -hT
Shows mounted file systems, associated mountpoints and file system types
umount /mountpoint
man command
who am i
clear
which command
mount /filesystem /mountpoint
man man
Determine who you are logged in as: (who you really are, real user)
Clear screen
netstat -r
netstat -i 1
ping -n host
netstat -i
ping host
telnet host
ssh username@address
sftp host
en {password}
sho int
disable
sho mac-address-table
sho arp