Saturday, October 3, 2009

Linux Commands - Viewing the Current Directory - 'pwd' and 'ls'


Linux Commands - Viewing the Current Directory - 'pwd' and 'ls'
If you are not familiar with the Linux file system, please read The Linux/Unix File System.
How Do I Know Which Directory I Am In?
Use the command pwd (print working directory),
$ pwd
/home/fredf
List Files, File Permissions, The Chmod Command
To list the files in a directory type ls,
$ ls
a.out file1.c file3 src

The option -a will show all the files in the directory,
$ ls -a
.bash_profile a.out file1.c file3 src
The special file .bash_profile is a configuration file which is used to configure the Bash shell when a user logs in.
Note that files starting with a dot are hidden files and are not displayed during a normal ls command. Hidden files are usually used to store configuration information for various programs.
The option -l will display a long listing,
$ ls -l
-rwxr-xr-x 1 fredf fredf 20987 Oct 10 10:04 a.out
-rwxr-xr-x 1 fredf fredf 1098 Mar 7 2005 file1.c
-rwxr-xr-x 1 fredf fredf 654 Jun 12 18:44 file3
drwxr-xr-x+ 1 fredf fredf 0 Jan 01 2005 src
The first column displays the permissions for the files. Permission attributes are changed with the chmod command.

No comments:

Post a Comment