Sie sind auf Seite 1von 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 “Print Working Directory” Display the name of the current working
directory
cd Change working directory back to home directory
cd /dir1/subdir Change working directory using absolute path
cd subdir Change working directory using relative paths (does not start with “/”)
cd .. Go back one directory level
mkdir dirname Creates a new directory with the name “dirname”.
rmdir dirname Removes or deletes the “empty” directory “dirname”.
rmdir –r 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 –a List contents of the current directory including hidden files
ls –l or ll List content of the current directory and include sizes, dates, and other information
about the file. Also known as “long listing”. (ll is an alias for ls –l)

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
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 –I filename dir_name/ Copy (or create a duplicate of ) a file to another directory:
cp –p old_file new_file Copy a file maintaining it permissions
rm -i filename Delete a file (or remove) from the current directory
mv old_name new_name Rename a file:
mv filename new_dir_name/ Move a file to another directory:
file filename Determine a files type:
more 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”.
less filename Like more but with better user interaction. Less is more!
head filename Shows only the top 10 lines (head) of the file “filename”.
tail filename Shows only the bottom 10 lines (tail) of the file “filename”.
tail –f 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 Show all occurrences of “rpg” in the file “hosts” in the /etc
directory.
ls /etc | grep host* 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
groupname “group”.
chmod g +x filename Modifies a files permissions. In this case, we are setting the
executable (x) flag to true (+) in the group (g) field.
chmod 744 filename 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
identification (PID):
ps -ef | grep user_id List current process status and PID for a certain user:
ps -fu user_id Gives the same result as above
pstree Lists processes in an orderly “tree” format.
kill PID Kill (or terminate) a process:
kill -9 PID Stop an unresponsive process:
NOTE: Use this command very carefully! It can have a drastic impact on your system. The kill PID
command is a better choice for terminating a process.
top Lists the top CPU resource users: (q to quit)

Miscellaneous Commands

su {password} Become the “Super User” (root). (Some also call it “Switch User)
su - {password} Become the “Super User” (root) and assume root’s environment (paths,
home directory, etc)
whoami Determine who you are logged in as: (effective user)
who am i Determine who you are logged in as: (who you really are, real user)
who –r Shows the current init state or run level
clear Clear screen
exit Exits the window or shell:
which command Determine the full path of a command or alias
df -hT Shows mounted file systems, associated mountpoints and file system types
mount /filesystem /mountpoint Mounts a file system to a target directory (mountpoint)
umount /mountpoint Unmounts a previously mounted filesystem (use df –hT to find
mountpoints and to print file system type)
man command Displays the manual (help) pages for command
man man Displays help on using the man command

Linux Network Commands

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


ifconfig eth0 down Shuts down the eth0 interface.
Ifconfig eth0 up Enables the eth0 interface.
netstat -r Shows the kernel routing table
netstat -i Show the kernel ip interface table ( look for input errors)
netstat -i 1 Show ip interfaces , update once per second “CTRL-c” to stop
ping host Elicit an echo response from the specified hosts. “CTRL-c” to stop
ping -n host Attempt ping once per “n” seconds.
telnet host Opens a terminal window with other hosts. “Ctrl ]” to escape.
(NOT RECOMMENDED; use ssh instead)
ssh username@address Used to securely “shell-in” to another processor or location
sftp host Opens a secure file transfer program to hosts
Tip: use it like you would ssh.
Some Basic Cisco commands

Switch
sho vlan brie Show vlans in brief format. NOTE: VLAN 2 acts as a separate switch.
Switch & Router
en {password} Turn on (enable) privileged commands
disable Turn off privileged commands
sho int Show status of all interfaces (except aux and con).
sho int fastethernet #/# Shows status of specific interface #/#.
sho run {priv} Show running configuration
sho mac-address-table Show mac to port associations
sho arp Show “arp” IP to physical address.
sho ip int brie Shows a brief summary status of IP interfaces
exit Log out of device

Das könnte Ihnen auch gefallen