skip navigation

www.Hilands.com


Content:: Using the command line in Linux

Understanding and using the command line
OS: Linux/Posix
Last Modified: 2013-03-26


Table of Contents
The Prompt
The prompts may vary, we're going to look into the basic default shell within Debian.
When logged in as a normal user
<user>@<system>:<path>$
My user, pallen. System name faileas.
pallen@faileas:~$

As a super user (root)
<user>@<system>:<path>#
root@faileas:~#
Pound (#) vs Dollar Sign ($)
You may notice at the end of the prompt you will see a Pound (#) or a Dollar Sign ($).
In Bash, generally speaking, the $ is a normal none administrative account while the # is used for administrative or super user accounts.

You'll notice that most of the command line queries on this site show a # or a $ sign infront of the command line examples! This will generally designate if the command needs to be run by a super user or not.
What is the tilde?
the tilde (~) path. home directory.
Basic Navigation
For the majority of our navigation we will be looking at "ls" (list/listing), "cd" (Change Directory), and "pwd" (Print Working Directory).

ls
List is a command that will show us what files and directories exist on the system. # ls /
bin   etc         lib    lost+found  opt   sbin     sys  var
boot  home        lib32  media       proc  selinux  tmp  vmlinuz
dev   initrd.img  lib64  mnt         root  srv      usr
The -l switch will print the directory listings in a "long listing format." It will show you the the file type, dictated by the first character, the permissions for the user, group and other. Followed by the number of linked hard-links then the user and group. The size of the file, the date and time the file was created, and the name of the file. # ls -l /
total 88
drwxr-xr-x   2 root root  4096 May 25 00:21 bin
drwxr-xr-x   3 root root  4096 Sep 11 19:24 boot
drwxr-xr-x  17 root root  3340 Nov 20 20:16 dev
drwxr-xr-x 121 root root  4096 Nov 20 20:16 etc
drwxr-xr-x   3 root root  4096 Apr  5  2012 home
lrwxrwxrwx   1 root root    30 Apr  5  2012 initrd.img -> boot/initrd.img-2.6.32-5-amd64
drwxr-xr-x  13 root root 12288 May 26 18:43 lib
drwxr-xr-x   4 root root  4096 Apr  6  2012 lib32
lrwxrwxrwx   1 root root     4 Apr  5  2012 lib64 -> /lib
drwx------   2 root root 16384 Apr  5  2012 lost+found
drwxr-xr-x   3 root root  4096 Jul 13 20:08 media
drwxr-xr-x   9 root root  4096 Oct 21 15:54 mnt
drwxr-xr-x  12 root root  4096 Nov 15 20:03 opt
dr-xr-xr-x 139 root root     0 Nov 20 10:29 proc
drwx------  17 root root  4096 Nov 13 20:46 root
drwxr-xr-x   2 root root  4096 Sep 11 19:24 sbin
drwxr-xr-x   2 root root  4096 Jul 20  2010 selinux
drwxr-xr-x   2 root root  4096 Apr  5  2012 srv
drwxr-xr-x  13 root root     0 Nov 20 10:29 sys
drwxrwxrwt   7 root root  4096 Nov 20 20:19 tmp
drwxr-xr-x  12 root root  4096 Apr  6  2012 usr
drwxr-xr-x  14 root root  4096 Apr  9  2012 var
lrwxrwxrwx   1 root root    27 Apr  5  2012 vmlinuz -> boot/vmlinuz-2.6.32-5-amd64
The -a switch will show all files, which includes normally hidden files that start with a period (.). # ls -la /
total 104
drwxr-xr-x  22 root root  4096 Mar  1 21:23 .
drwxr-xr-x  22 root root  4096 Mar  1 21:23 ..
drwxr-xr-x   2 root root  4096 Mar  1 20:50 bin
drwxr-xr-x   3 root root  4096 Mar  1 21:23 boot
drwxr-xr-x  17 root root  3340 Mar 26 18:36 dev
drwxr-xr-x 121 root root  4096 Mar 26 18:36 etc
drwxr-xr-x   3 root root  4096 Apr  5  2012 home
lrwxrwxrwx   1 root root    30 Apr  5  2012 initrd.img -> boot/initrd.img-2.6.32-5-amd64
drwxr-xr-x  13 root root 12288 Mar  1 20:51 lib
drwxr-xr-x   4 root root 12288 Mar  1 20:50 lib32
lrwxrwxrwx   1 root root     4 Apr  5  2012 lib64 -> /lib
drwx------   2 root root 16384 Apr  5  2012 lost+found
drwxr-xr-x   3 root root  4096 Jul 13  2012 media
drwxr-xr-x   9 root root  4096 Oct 21 15:54 mnt
drwxr-xr-x  12 root root  4096 Nov 15 20:03 opt
dr-xr-xr-x 138 root root     0 Mar 26 11:11 proc
drwx------  17 root root  4096 Mar 13 20:16 root
drwxr-xr-x   2 root root  4096 Feb 15 19:30 sbin
drwxr-xr-x   2 root root  4096 Jul 20  2010 selinux
drwxr-xr-x   2 root root  4096 Apr  5  2012 srv
drwxr-xr-x  13 root root     0 Mar 26 11:11 sys
drwxrwxrwt   7 root root  4096 Mar 26 18:42 tmp
drwxr-xr-x  12 root root  4096 Apr  6  2012 usr
drwxr-xr-x  14 root root  4096 Apr  9  2012 var
lrwxrwxrwx   1 root root    27 Apr  5  2012 vmlinuz -> boot/vmlinuz-2.6.32-5-amd64
cd
Navigation through the folders in the command line can be done with the Change Directory, or cd, command.
The root directory of the file system contains all of the directories and files on the system. A directory on many GUI based systems is called a folder. The root directory is designated simply as a forward slash (/).
To navigate to the root directory you can use the command $ cd /
You can navitate to the etc folder from the root directory two ways. $ cd etc/
or $ cd /etc/
The trailing slash is not a requirement but will help differentiate between a file and a folder.
The change directory command with the initiating forward slash tells the command to start at the root directory where the command without the initiating forward slash tells the command to start at the current working directory.
The current working directory is the location of the directory you are currently in.
You can navigate one directory up by change to the parent directory with a shorthand notation of ".." note that a single "." refers to current location.

from the etc directory we can go back to the root directory one of two ways.
By going to the parent directory, one level up with $ cd ..
or by going directly to the root directory. $ cd /
pwd
Print Working Directory, pwd, will display what your current directory including the full path. $ pwd From the root directory you will see
/
From the etc directory you will see
/etc
clear
Shutting down your system
The shutdown command will require an action switch and the time you want the shutdown action to take place.
To shut the system down you will want to use the -h switch. This will "Halt" the system. # shutdown -h now
If we would like the system to reboot right after it has been shutdown we can use the -r switch. # shutdown -r now
Alternatively we can use the reboot command to restart the system. # reboot
Finding files
find / -name
Wild Cards
wild cards * ?
Piping Standard Out
piping > | grep , more , less ls -l |grep ^d
Users/etc
chmod
chown
w
References