Some more useful Linux commands

By Ali Hammad Baig on 11:17 AM

Filed Under:

File & Directory Commands

  • pwd: The pwd command will allow you to know in which directory you're located ( pwd stands for "print working directory"). Example: "pwd" in the Desktop directory will show "~/Desktop". Note that the Gnome Terminal also displays this information in the title bar of it's window - see the example screenshot at the top of this page.
  • ls: The ls command will show you the files in your current directory. Used with certain options, you can see sizes of files, when files where made, and permissions of files. Example: "ls ~" will show you the files that are in your home directory.
  • cd: The cd command will allow you to change directories. When you open a terminal you will be in your home directory. To move around the file system you will use cd. Examples:
    • To navigate into the root directory, use "cd /"

    • To navigate to your home directory, use "cd" or "cd ~"

    • To navigate up one directory level, use "cd .."

    • To navigate to the previous directory (or back), use "cd -"

    • To navigate through multiple levels of directory at once, specify the full directory path that you want to go to. For example, use, "cd /var/www" to go directly to the /www subdirectory of /var/. As another example, "cd ~/Desktop" will move you to the Desktop subdirectory inside your home directory.

  • cp: The cp command will make a copy of a file for you. Example: "cp file foo" will make a exact copy of "file" and name it "foo", but the file "file" will still be there. When you use mv that file would no longer exist, but when you use cp the original file stays and a new copy is made.
  • mv: The mv command will move a file to a different location or will rename a file. Examples are as follows: "mv file foo" will rename the file "file" to "foo". "mv foo ~/Desktop" will move the file "foo" to your Desktop directory but will not rename it. You must specify a new file name to rename a file.
    • To save on typing, you can substitute '~' in place of the home directory.

    • Note that if you are using mv with sudo you will not be able to use the ~ shortcut, but will have to use the full pathnames to your files. This is because when you are working as root, ~ will refer to the root account's home directory, not your own.

  • rm: Use this command to remove or delete a file in your directory. It will not work on directories which have files in them (use rmdir instead).

  • mkdir: The mkdir command will allow you to create directories. Example: "mkdir music" will create a music directory.

  • man: The man command is used to show you the manual of other commands. Try "man man" to get the man page for man itself. See the " Man & Getting Help" section down the page for more information.

System Information Commands

  • df: The df command displays filesystem disk space usage for all partitions. " df -h" is probably the most useful - it uses megabytes (M) and gigabytes (G) instead of blocks to report. ( -h means "human-readable")

  • free: The free command displays the amount of free and used memory in the system. "free -m" will give the information using megabytes, which is probably most useful for current computers.

  • top: The top command displays information on your Linux system, running processes and system resources, including CPU, RAM & swap usage and total number of tasks being run. To exit top, press "q".

  • uname -a: The uname command with the -a option prints all system information, including machine name, kernel name & version, and a few other details. Most useful for checking which kernel you're using.

  • ifconfig reports on your system's network interfaces.
  • lsb_release -a: The lsb_release command with the -a option prints version information for the Linux release you're running, for example:

      user@computer:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 6.06 LTS
Release: 6.06
Codename: dapper

Network Commands

  • netstat: Displays contents of /proc/net files. It works with the Linux Network Subsystem, it will tell you what the status of ports are ie. open, closed, waiting, masquerade connections. It will also display various other things. It has many different options.
  • tcpdump: This is a sniffer, a program that captures packets off a network interface and interprets them for you. It understands all basic internet protocols, and can be used to save entire packets for later inspection.
  • ping: The ping command (named after the sound of an active sonar system) sends echo requests to the host you specify on the command line, and lists the responses received their round trip time. You simply use ping as:
  • ping ip_or_host_name
  • hostname: Tells the user the host name of the computer they are logged into. Note: may be called host.

  • traceroute: traceroute will show the route of a packet. It attempts to list the series of hosts through which your packets travel on their way to a given destination. Also have a look at xtraceroute (one of several graphical equivalents of this program).

Command syntax:

traceroute machine_name_or_ip

  • tracepath: tracepath performs a very simlar function to traceroute the main difference is that tracepath doesn't take complicated options.

Command syntax:

tracepath machine_name_or_ip

  • findsmb: findsmb is used to list info about machines that respond to SMB name queries (for example windows based machines sharing their hard disk's).

Command syntax:


This would find all machines possible, you may need to specify a particular subnet to query those machines only...

  • nmap: “ network exploration tool and security scanner”. nmap is a very advanced network tool used to query machines (local or remote) as to whether they are up and what ports are open on these machines.

A simple usage example:

nmap machine_name

This would query your own machine as to what ports it keeps open. nmap is a very powerful tool, documentation is available on the nmap site as well as the information in the manual page.

  • route: The route command is the tool used to display or modify the routing table. To add a gateway as the default you would type:
route add default gw some_computer
  • ifconfig: This command is used to configure network interfaces, or to display their current configuration. In addition to activating and deactivating interfaces with the “up” and “down” settings, this command is necessary for setting an interface's address information if you don't have the ifcfg script.

Use ifconfig as either:


This will simply list all information on all network devices currently up.

ifconfig eth0 down

This will take eth0 (assuming the device exists) down, it won't be able to receive or send anything until you put the device back “up” again.

Clearly there are a lot more options for this tool, you will need to read the manual/info page to learn more about them.

  • ifup: Use ifup device-name to bring an interface up by following a script (which will contain your default networking settings). Simply type ifup and you will get help on using the script.

For example typing:

ifup eth0

Will bring eth0 up if it is currently down.

  • ifdown: Use ifdown device-name to bring an interface down using a script (which will contain your default network settings). Simply type ifdown and you will get help on using the script.

For example typing:

ifdown eth0

Will bring eth0 down if it is currently up.

  • ifcfg: Use ifcfg to configure a particular interface. Simply type ifcfg to get help on using this script.

For example, to change eth0 from to you could do:

ifcfg eth0 del
ifcfg eth0 add

The first command takes eth0 down and removes that stored IP address and the second one brings it back up with the new address.

  • host: Performs a simple lookup of an internet address (using the Domain Name System, DNS). Simply type:
host ip_address


host domain_name
dig: The "domain information groper" tool. More advanced then host... If you give a hostname as an argument to output information about that host, including it's IP address, hostname and various other information.

For example, to look up information about “” type:


To find the host name for a given IP address (ie a reverse lookup), use dig with the `-x' option.

dig -x

This will look up the address (which may or may not exist) and returns the address of the host, for example if that was the address of “” then it would return “”.

dig takes a huge number of options (at the point of being too many), refer to the manual page for more information.

whois: (now BW whois) is used to look up the contact information from the “whois” databases, the servers are only likely to hold major sites. Note that contact information is likely to be hidden or restricted as it is often abused by crackers and others looking for a way to cause malicious damage to organisation's.

wget: (GNU Web get) used to download files from the World Wide Web.

To archive a single web-site, use the -m or --mirror (mirror) option.

Use the -nc (no clobber) option to stop wget from overwriting a file if you already have it.

Use the -c or --continue option to continue a file that was unfinished by wget or another program.

Simple usage example:

wget url_for_file

This would simply get a file from a site.

wget can also retrieve multiple files using standard wildcards, the same as the type used in bash, like *, [ ], ?. Simply use wget as per normal but use single quotation marks (' ') on the URL to prevent bash from expanding the wildcards. There are complications if you are retrieving from a http site (see below...).

Advanced usage example, (used from wget manual page):

wget --spider --force-html -i bookmarks.html

This will parse the file bookmarks.html and check that all the links exist.

Advanced usage: this is how you can download multiple files using http (using a wildcard...).

Notes: http doesn't support downloading using standard wildcards, ftp does so you may use wildcards with ftp and it will work fine. A work-around for this http limitation is shown below:

wget -r -l1 --no-parent -A.gif[1]

This will download (recursively), to a depth of one, in other words in the current directory and not below that. This command will ignore references to the parent directory, and downloads anything that ends in “.gif”. If you wanted to download say, anything that ends with “.pdf” as well than add a -A.pdf before the website address. Simply change the website address and the type of file being downloaded to download something else. Note that doing -A.gif is the same as doing -A “*.gif” (double quotes only, single quotes will not work).

wget has many more options refer to the examples section of the manual page, this tool is very well documented.


curl: curl is another remote downloader. This remote downloader is designed to work without user interaction and supports a variety of protocols, can upload/download and has a large number of tricks/work-arounds for various things. It can access dictionary servers (dict), ldap servers, ftp, http, gopher, see the manual page for full details.

To access the full manual (which is huge) for this command type:

curl -M

For general usage you can use it like wget. You can also login using a user name by using the -u option and typing your username and password like this:

curl -u username:password http://www.placetodownload/file

To upload using ftp you the -T option:

curl -T file_name

To continue a file use the -C option:

curl -C - -o file

0 comments for this post

Post a Comment

Blog Widget by LinkWithin