Monday, March 17, 2014

4:38 PM
Good day!

Hello and welcome to another article on my howto; this time we will learn the basics on how to use the pwd and ls commands effectively on *nix.These commands are to be run from the shell command prompt. that is if you are actually on a Linux/UNIX system using ssh, the $ and # are command prompts.

This is the second part of my howto in "Learning Linux/UNIX"


pwd

print name of current/working directory. The pwd command is considered as one of the most frequently used commands on Linux, AIX, HP-UX, *BSD, and other UNIX like operating systems along with the ls, and cd commands.

At the UNIX prompt type the pwd command, it will show you the current working directory you are in.

usage          :    pwd [-LP]


examples  :
----------------

# pwd                             - if you have the root account the # prompt also
/root                               - means you are a super-user
#

or...
This will print out the current directory 

$ pwd
/home/index
$

Assuming you are "index" on the system and you wanted to move down to the john directory (you also own this) that contains the files that you wanted to check. You would type in like this

$ cd ~/john or cd /home/john
$ pwd
/home/john

Going back one directory up type in:

$ cd ..

or going to your parent directory (your home) just type in `cd` or `cd ~`




ls


list directory contents. The ls command is used to list directory contents under Linux and Unix like operating systems. If no options or operands are given, the contents of the current directory are displayed on the screen.

Listing file directories assuming you are in your home directory:

$ pwd
/home/index
$ ls
Documents
Downloads
Music
Public
Desktop
Videos
Pictures

To list and include hidden files, type..

$ ls -a
:
:
.bash_history
.bash_logout
.bashrc
.profile
.vim

To list file names in john's directory, type..

$ ls ~/john
$ ls /home/john

ls -l

The `ls -l` is an important command in unix. This command displays the whole directory in long format, if you try to run this in parent direcory, you will have..

total 144
drwxrwxr-x  9 index- index-  4096 Feb  3 14:29    apache-tomcat-8.0.1
-rw-rw-r--      1 index- index-   263   Feb 25 16:13  app_letter.txt
        :                    :                  :                   :                     :               :
        :                    :                  :                   :                     :               :
-rw-rw-r--      1 index- index-   158   Mar  2 03:48   notes.txt
        :                    :                  :                   :                     :               :

$

The total 144 tells one the amount of disk space used in a directory.

0 comments:

Post a Comment