You are on page 1of 5

Basic Linux Commands

This list is not intended to be an in-depth description of each command.


In some cases, it provides only one use of the commands.

Directory Commands
pwd
cd

cd /dir1/subdir
cd subdir

Print Working Directory Display the name of the current working


directory

Change working directory back to home directory


Change working directory using absolute path

Change working directory using relative paths (does not start with /)

cd ..

Go back one directory level

rmdir dirname

Removes or deletes the empty directory dirname.

mkdir dirname
rmdir r dirname

Creates a new directory with the name dirname.


Recursively removes or deletes the directory dirname and EVERYTHING below it.
Use with EXTREME caution!

File Commands
ls

List contents of the current directory

ls l or ll

List content of the current directory and include sizes, dates, and other information

ls al

Combines the attributes of the a and the l switches

ls | more

List content of the current directory and pause when page is full

ls a

List contents of the current directory including hidden files


about the file. Also known as long listing. (ll is an alias for ls l)

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

Copy (or create a duplicate of) a file

cp p old_file new_file

Copy a file maintaining it permissions

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

Copy (or create a duplicate of ) a file to another directory:


Delete a file (or remove) from the current directory
Rename a file:

Move a file to another directory:


Determine a files type:

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 more but with better user interaction. Less is more!


Shows only the top 10 lines (head) of the file filename.

Shows only the bottom 10 lines (tail) of the file filename.

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:

? means "any single letter"


* means "anything at all"
Examples:
ls ?? will list all files with two-letter names
ls p* will list all files that start with "p"

grep is useful in searching for specific strings in file names or file contents.
Examples:
grep rpg /etc/hosts
ls /etc | grep host*

Show all occurrences of rpg in the file hosts in the /etc


directory.

List the /etc directory, only returning filenames beginning with


host.

Ownerships and permissions


The format of permission groups is: owner/group/others. The format of the permissions within each
segment is read/write/execute. This can be shown using the ll or long list command in the
illustration below.

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.

chown user:group filename

Changes ownership of the file filename to the username user and

chmod g +x filename

Modifies a files permissions. In this case, we are setting the

chmod 744 filename

groupname group.

executable (x) flag to true (+) in the group (g) field.

Similar to above. Modifies the permissions of the file filename using


an octal format. In this case the owner has full (read/write/execute)
permissions, with group and others having only read permissions.

Process Commands
ps -ef

List the status of current process (or running programs) and its process

ps -ef | grep user_id

List current process status and PID for a certain user:

ps -fu user_id

identification (PID):

Gives the same result as above

pstree

Lists processes in an orderly tree format.

kill -9 PID

Stop an unresponsive process:

kill PID

Kill (or terminate) a process:

NOTE: Use this command very carefully! It can have a drastic impact on your system. The kill PID

top

command is a better choice for terminating a process.

Lists the top CPU resource users: (q to quit)

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

Determine who you are logged in as: (effective user)

who r

Shows the current init state or run level

exit

Exits the window or shell:

df -hT

Shows mounted file systems, associated mountpoints and file system types

umount /mountpoint

Unmounts a previously mounted filesystem (use df hT to find

man command

Displays the manual (help) pages for 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

Determine the full path of a command or alias


Mounts a file system to a target directory (mountpoint)
mountpoints and to print file system type)
Displays help on using the man command

Linux Network Commands


Ifconfig -a

ifconfig eth0 down


Ifconfig eth0 up

Displays current configuration of all (-a) network interfaces.


Shuts down the eth0 interface.
Enables the eth0 interface.

netstat -r

Shows the kernel routing table

netstat -i 1

Show ip interfaces , update once per second CTRL-c to stop

ping -n host

Attempt ping once per n seconds.

netstat -i
ping host

telnet host

ssh username@address
sftp host

Show the kernel ip interface table ( look for input errors)


Elicit an echo response from the specified hosts. CTRL-c to stop
Opens a terminal window with other hosts. Ctrl ] to escape.
(NOT RECOMMENDED; use ssh instead)

Used to securely shell-in to another processor or location


Opens a secure file transfer program to hosts

Tip: use it like you would ssh.

Some Basic Cisco commands


Switch

sho vlan brie

Switch & Router

Show vlans in brief format. NOTE: VLAN 2 acts as a separate switch.

en {password}

Turn on (enable) privileged commands

sho int

Show status of all interfaces (except aux and con).

disable

Turn off privileged commands

sho int fastethernet #/#

Shows status of specific interface #/#.

sho run {priv}

sho mac-address-table
sho arp

sho ip int brie


exit

Show running configuration

Show mac to port associations

Show arp IP to physical address.


Shows a brief summary status of IP interfaces
Log out of device

You might also like