File and Directory Basic Commands for Linux Beginners

Since past few years many users were start buying Linux Laptop, which indicates the Linux desktop operating system is gaining more users.

What’s stopping users to not to buy Linux laptop? i hope, they may think, it’s very hard to use.

If so, your perception is not correct since Linux desktop operating systems are better than Windows as per my personal experience.

As i’m using Linux laptop since 2014 and don’t feel to go back to Windows.

If you are planning to move from Windows to Linux but you don’t know where to start?

Don’t worry, you are in the right page and you can start right form here. We are here to make you to understand about Linux basic commands for file and direcotry management.

I have prepared File and Directory Basics Commands in-depth for Linux Beginners.

In this article, i have added 10 Linux commands, which is related to file and directory management.

Command Short Description
ls Lists the contents of a directory
cp Copy files
mv Rename files
rm Delete files
cd Change directory
pwd Print current Working directory name
ln Link files
mkdir Create directory
rmdir To Delete Empty directory only

1) What is ls ?

The ls command prints to standard output of the current directory contents. If you mention any specified directory or parameter the output will be shows what which you mentioned. Many option is there in ls command you can use those option to print the output with detailed information, ls command is heart of Linux user and the Linux user can’t work/live without using ls command in Linux environment.

Syntax : ls [options] [pathnames]

Example : ls command

# ls -l
total 274840
-rw-------. 1 root root      1369 Apr 30  2013 anaconda-ks.cfg
-rw-r--r--  1 root root       176 Nov 14 10:10 bash_profile_14-11-2013
-rw-r--r--  1 root root       351 Nov 30 10:50 bash_profile_30-11-2013
-rwxr-xr-x  1 root root        91 Jun 20 16:35 gg.sh
-rw-r--r--. 1 root root     16959 Apr 30  2013 install.log
-rw-r--r--. 1 root root      5820 Apr 30  2013 install.log.syslog
-rw-r--r--  1 root root  76676480 Jun 20 08:06 2daygeek-l.sql
-rw-r--r--  1 root root 186298108 May  3  2013 mysql-5.5.25-linux2.6-x86_64.tar.gz
drwxr-xr-x  2 root root      4096 Sep 17 15:30 mysql-tables
-rw-r--r--  1 root root  18114860 Nov 29 14:05 test-2daygeek.sql.gz

2) What is cp ?

Copies files or folders/directory from one location to another.

Syntax : cp [options] [Source] [Destination]

Example : cp command

Now, i’m going to copy a “test-file” from /home/2daygeek directory to /home/mageshm directory. See the output.

# cp test-file /home/mageshm/
# ls -l
total 40K
drwx------.  5 mageshm mageshm 4.0K Dec  7 08:27 ./
drwx--x--x. 16 root    root    4.0K Nov 27 01:16 ../
-rw-------.  1 mageshm mageshm  457 Dec  4 13:31 .bash_history
-rw-r--r--.  1 mageshm mageshm   18 May 10  2012 .bash_logout
-rw-r--r--.  1 mageshm mageshm  176 May 10  2012 .bash_profile
-rw-r--r--.  1 mageshm mageshm  124 May 10  2012 .bashrc
drwxrwxr-x.  2 mageshm mageshm 4.0K Nov 16 10:14 perl5/
drwxr-xr-x.  2 mageshm mageshm 4.0K Nov 16 10:07 public_ftp/
drwxr-xr-x.  3 mageshm mageshm 4.0K Nov 16 10:07 public_html/
-rw-r--r--.  1 mageshm mageshm    5 Dec  7 08:27 test-file

3) What is mv ?

mv is a Unix command that moves one or more files or directories from one place to another. It is also used to rename a files.

Syntax : mv [Options] [OldName] [NewName]

Example : mv command

Now, i’m going to move a “test-file” from /home/mageshm directory to /home/2daygeek directory. See the output. The file is not there in present directory becasue its moved to destination directory.

# mv test-file /home/2daygeek
# ll -h
total 36K
drwx------.  5 mageshm mageshm 4.0K Dec  7 08:47 ./
drwx--x--x. 16 root    root    4.0K Nov 27 01:16 ../
-rw-------.  1 mageshm mageshm  457 Dec  4 13:31 .bash_history
-rw-r--r--.  1 mageshm mageshm   18 May 10  2012 .bash_logout
-rw-r--r--.  1 mageshm mageshm  176 May 10  2012 .bash_profile
-rw-r--r--.  1 mageshm mageshm  124 May 10  2012 .bashrc
drwxrwxr-x.  2 mageshm mageshm 4.0K Nov 16 10:14 perl5/
drwxr-xr-x.  2 mageshm mageshm 4.0K Nov 16 10:07 public_ftp/
drwxr-xr-x.  3 mageshm mageshm 4.0K Nov 16 10:07 public_html/

If i’m checking a “test-file” in /home/2daygeek directory its found because its moved from /home/mageshm

# cd /home/2daygeek
# ll -h
total 40K
drwx------.  5 2daygeek 2daygeek 4.0K Dec  7 08:47 ./
drwx--x--x. 16 root     root     4.0K Nov 27 01:16 ../
-rw-------.  1 2daygeek 2daygeek  663 Nov 19 15:23 .bash_history
-rw-r--r--.  1 2daygeek 2daygeek   18 May 10  2012 .bash_logout
-rw-r--r--.  1 2daygeek 2daygeek  176 May 10  2012 .bash_profile
-rw-r--r--.  1 2daygeek 2daygeek  124 May 10  2012 .bashrc
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 perl5/
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 public_ftp/
drwxrwxr-x.  3 2daygeek 2daygeek 4.0K Nov 19 10:12 public_html/
-rw-r--r--.  1 mageshm  mageshm     5 Dec  7 08:27 test-file

4) What is rm ?

rm is a basic UNIX command used to remove objects such as files, directories, device nodes, symbolic links, etc..

Syntax : mv [Options] [fileNames | directory]

Example : rm command

The earlier example we have moved one file from /home/mageshm to /home/2daygeek directory and now i’m going to create new directory called “test-dir” and delete the moved file & delete the newly created directory.

# mkdir test-dir
# ll -h
total 44K
drwx------.  6 2daygeek 2daygeek 4.0K Dec  7 08:57 ./
drwx--x--x. 16 root     root     4.0K Nov 27 01:16 ../
-rw-------.  1 2daygeek 2daygeek  663 Nov 19 15:23 .bash_history
-rw-r--r--.  1 2daygeek 2daygeek   18 May 10  2012 .bash_logout
-rw-r--r--.  1 2daygeek 2daygeek  176 May 10  2012 .bash_profile
-rw-r--r--.  1 2daygeek 2daygeek  124 May 10  2012 .bashrc
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 perl5/
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 public_ftp/
drwxrwxr-x.  3 2daygeek 2daygeek 4.0K Nov 19 10:12 public_html/
drwxr-xr-x.  2 root     root     4.0K Dec  7 08:57 test-dir/
-rw-r--r--.  1 mageshm  mageshm     5 Dec  7 08:27 test-file

Now, i’m going to delete a file called “test-file”.

# rm -i test-file
rm: remove regular file `test-file'? yes

Now, i’m going to delete a directory called “test-dir”.

# rm -Ri test-dir/
rm: remove directory `test-dir'? yes

Here i’m going to check whether the file and folder is got deleted or present it. It’s not there because its already deleted.

# ll -h
total 36K
drwx------.  5 2daygeek 2daygeek 4.0K Dec  7 08:59 ./
drwx--x--x. 16 root     root     4.0K Nov 27 01:16 ../
-rw-------.  1 2daygeek 2daygeek  663 Nov 19 15:23 .bash_history
-rw-r--r--.  1 2daygeek 2daygeek   18 May 10  2012 .bash_logout
-rw-r--r--.  1 2daygeek 2daygeek  176 May 10  2012 .bash_profile
-rw-r--r--.  1 2daygeek 2daygeek  124 May 10  2012 .bashrc
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 perl5/
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 public_ftp/
drwxrwxr-x.  3 2daygeek 2daygeek 4.0K Nov 19 10:12 public_html/

5) What is cd ?

cd mean (change directory), is a command line argument used to change the current working directory.

Syntax : cd [directory]

Example : cd command

Now, i’m in “/home/2daygeek” directory and i want to change “/home/mageshm” directory

# ll -h
total 36K
drwx------.  5 2daygeek 2daygeek 4.0K Dec  7 08:59 ./
drwx--x--x. 16 root     root     4.0K Nov 27 01:16 ../
-rw-------.  1 2daygeek 2daygeek  663 Nov 19 15:23 .bash_history
-rw-r--r--.  1 2daygeek 2daygeek   18 May 10  2012 .bash_logout
-rw-r--r--.  1 2daygeek 2daygeek  176 May 10  2012 .bash_profile
-rw-r--r--.  1 2daygeek 2daygeek  124 May 10  2012 .bashrc
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 perl5/
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 public_ftp/
drwxrwxr-x.  3 2daygeek 2daygeek 4.0K Nov 19 10:12 public_html/

To change the directory.

# cd /home/mageshm
[email protected] [/home/mageshm]# pwd
/home/mageshm

6) What is pwd ?

The “pwd” command (print working directory) is used to output the path of the current working directory.

Syntax : pwd

Example : pwd command

Here i can’t able to understand, in which directory i’m working.

# ll -h
total 4.6M
-rwxrwxrwx  1 mrjale ftpaccounts 1.5K Jun 20 07:32 activation.php
-rwxr-xr-x  1 root   root         199 Sep 23 15:52 adilabad
-rwxr-xr-x  1 root   root         199 Sep 23 15:52 adoni
-rwxr-xr-x  1 root   root         199 Sep 23 15:52 agartala
-rwxrwxrwx  1 mrjale ftpaccounts  12K Jun 20 07:32 ajax.php
-rwxrwxrwx  1 mrjale ftpaccounts 1.9K Jun 20 07:32 alert1.html
-rwxrwxrwx  1 mrjale ftpaccounts 1.5K Jun 20 07:32 alerts.php
drwxrwxrwx  4 mrjale ftpaccounts 4.0K Sep 21 16:15 backup
-rw-r--r--  1 mrjale ftpaccounts  45K Sep 20 16:33 bootstrap.min.css
-rw-r--r--  1 mrjale ftpaccounts  45K Sep 20 11:47 bootstrap.min.css_bk_20sep2013
-rwxrwxrwx  1 mrjale ftpaccounts  15K Jun 20 07:32 CHANGELOG.txt
-rw-r--r--  1 mrjale ftpaccounts  13K Aug 27 15:12 chosen.css

I’m just put the “pwd” on current directory and get the exact path location.

# pwd
/u01/zend/apache2/htdocs/www.2daygeek.com

7) What is mkdir ?

mkdir is a basic UNIX command is used to create a new directory

Syntax : mkdir [option] [Directory]

Example : mkdir command

Now, i’m going to create the new directory called “test-dir”

# mkdir test-dir
# ll -h
total 44K
drwx------.  6 2daygeek 2daygeek 4.0K Dec  7 08:57 ./
drwx--x--x. 16 root     root     4.0K Nov 27 01:16 ../
-rw-------.  1 2daygeek 2daygeek  663 Nov 19 15:23 .bash_history
-rw-r--r--.  1 2daygeek 2daygeek   18 May 10  2012 .bash_logout
-rw-r--r--.  1 2daygeek 2daygeek  176 May 10  2012 .bash_profile
-rw-r--r--.  1 2daygeek 2daygeek  124 May 10  2012 .bashrc
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 perl5/
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 public_ftp/
drwxrwxr-x.  3 2daygeek 2daygeek 4.0K Nov 19 10:12 public_html/
drwxr-xr-x.  2 root     root     4.0K Dec  7 08:57 test-dir/
-rw-r--r--.  1 mageshm  mageshm     5 Dec  7 08:27 test-file

8) What is rmdir ?

rmdir is a basic UNIX command is used to delete a empty directory.

Syntax : rmdir [option] [Directory]

Example : rmdir command

Now, i’m going to create the new directory called “test-dir”

# rm test-dir
# ll -h
total 44K
drwx------.  6 2daygeek 2daygeek 4.0K Dec  7 08:57 ./
drwx--x--x. 16 root     root     4.0K Nov 27 01:16 ../
-rw-------.  1 2daygeek 2daygeek  663 Nov 19 15:23 .bash_history
-rw-r--r--.  1 2daygeek 2daygeek   18 May 10  2012 .bash_logout
-rw-r--r--.  1 2daygeek 2daygeek  176 May 10  2012 .bash_profile
-rw-r--r--.  1 2daygeek 2daygeek  124 May 10  2012 .bashrc
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 perl5/
drwxrwxr-x.  2 2daygeek 2daygeek 4.0K Nov 19 10:12 public_ftp/
drwxrwxr-x.  3 2daygeek 2daygeek 4.0K Nov 19 10:12 public_html/
-rw-r--r--.  1 mageshm  mageshm     5 Dec  7 08:27 test-file

9) What is ln ?

Creates a link to a file or directory.

Syntax : ln [Existing file/folder path] [NewName]

Example : rmdir command

Now, i’m in “/home/mageshm/links/soft-link” directory and created one file called “test-soft-link” and one folder called “test-soft-link-folder” to create the soft link.

# nano test-soft-link
# mkdir test-soft-link-folder
# ll -h
total 16K
drwxr-xr-x. 3 mageshm mageshm 4.0K Dec  7 09:39 ./
drwxr-xr-x. 3 mageshm mageshm 4.0K Dec  7 09:37 ../
-rw-r--r--. 1 mageshm mageshm   16 Dec  7 09:38 test-soft-link
drwxr-xr-x. 2 mageshm mageshm 4.0K Dec  7 09:39 test-soft-link-folder/

I’m back to “/home/mageshm” directory. To create a soft link

# cd /home/mageshm
# ll -h
total 40K
drwx------.  6 mageshm mageshm 4.0K Dec  7 09:36 ./
drwx--x--x. 16 root    root    4.0K Nov 27 01:16 ../
-rw-------.  1 mageshm mageshm  457 Dec  4 13:31 .bash_history
-rw-r--r--.  1 mageshm mageshm   18 May 10  2012 .bash_logout
-rw-r--r--.  1 mageshm mageshm  176 May 10  2012 .bash_profile
-rw-r--r--.  1 mageshm mageshm  124 May 10  2012 .bashrc
drwxr-xr-x.  3 mageshm mageshm 4.0K Dec  7 09:37 links/
drwxrwxr-x.  2 mageshm mageshm 4.0K Nov 16 10:14 perl5/
drwxr-xr-x.  2 mageshm mageshm 4.0K Nov 16 10:07 public_ftp/
drwxr-xr-x.  3 mageshm mageshm 4.0K Nov 16 10:07 public_html/

Now, i’m going to create a soft link to file and folder

# ln -s /links/soft-link/test-soft-link s-link-file
# ln -s /links/soft-link/test-soft-link-folder s-link-folder

Both soft link has been created, you can see the output.

# ll -h
total 40K
drwx------.  6 mageshm mageshm 4.0K Dec  7 09:42 ./
drwx--x--x. 16 root    root    4.0K Nov 27 01:16 ../
-rw-------.  1 mageshm mageshm  457 Dec  4 13:31 .bash_history
-rw-r--r--.  1 mageshm mageshm   18 May 10  2012 .bash_logout
-rw-r--r--.  1 mageshm mageshm  176 May 10  2012 .bash_profile
-rw-r--r--.  1 mageshm mageshm  124 May 10  2012 .bashrc
drwxr-xr-x.  3 mageshm mageshm 4.0K Dec  7 09:37 links/
drwxrwxr-x.  2 mageshm mageshm 4.0K Nov 16 10:14 perl5/
drwxr-xr-x.  2 mageshm mageshm 4.0K Nov 16 10:07 public_ftp/
drwxr-xr-x.  3 mageshm mageshm 4.0K Nov 16 10:07 public_html/
lrwxrwxrwx.  1 root    root      31 Dec  7 09:41 s-link-file -> /links/soft-link/test-soft-link
lrwxrwxrwx.  1 root    root      38 Dec  7 09:42 s-link-folder -> /links/soft-link/test-soft-link-folder

Here you can understand the soft link of file “s-link-file” how to linked to actual path

# ls -l s-link-file
lrwxrwxrwx. 1 root root 31 Dec  7 09:41 s-link-file -> /links/soft-link/test-soft-link

Here you can understand the soft link of folder “s-link-folder” how to linked to actual path

# ls -l s-link-folder
lrwxrwxrwx. 1 root root 38 Dec  7 09:42 s-link-folder -> /links/soft-link/test-soft-link-folder

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...