Linux Commands – File Operations – Continued


Renaming files

There is no special command to rename a file or directory. But we can use mv to do the same.

Copying and Removing directories

Using -R option we can apply cp and rm to directories also.

Using -f in case of rm forces the delete.

Example


vishnu@bios-11:~$ ls
Desktop    Downloads         Music     Public     Ubuntu One
Documents  examples.desktop  Pictures  Templates  Videos
vishnu@bios-11:~$ mkdir test
vishnu@bios-11:~$ ls
Desktop    Downloads         Music     Public     test        Videos
Documents  examples.desktop  Pictures  Templates  Ubuntu One
vishnu@bios-11:~$ mv test/ temp
vishnu@bios-11:~$ ls
Desktop    Downloads         Music     Public  Templates   Videos
Documents  examples.desktop  Pictures  temp    Ubuntu One
vishnu@bios-11:~$ cp -R temp Documents/
vishnu@bios-11:~$ ls
Desktop    Downloads         Music     Public  Templates   Videos
Documents  examples.desktop  Pictures  temp    Ubuntu One
vishnu@bios-11:~$ rm temp
rm: cannot remove `temp': Is a directory
vishnu@bios-11:~$ rm -Rf temp
vishnu@bios-11:~$ ls
Desktop    Downloads         Music     Public     Ubuntu One
Documents  examples.desktop  Pictures  Templates  Videos
vishnu@bios-11:~$ cd ./Documents/
vishnu@bios-11:~/Documents$ ls
blog  docs  learn  task list  temp
vishnu@bios-11:~/Documents$ rmdir temp
vishnu@bios-11:~/Documents$ ls
blog  docs  learn  task list
There are a lot of options for almost every command. So it is a good practise to read the man page of every new command we learn 🙂

How to add an ordinary user to the SUDOers list?


In the UNIX system, an ordinary user doesn’t have privileges to do everything he wants. A root user is the ultimate user. Some actions need Super User privilege. Super users can do such tasks using the sudo command. However ordinary users who are not in the sudoers list cannot do such tasks even with the sudo command. Only a root user can install, upgrade or remove programs or softwares. This article is about how you can add an ordinary user to the sudoers list.

You need to use the visudo command to edit the sudoers list. Off course you’ll need root access to use the visudo command.creaters of Linux aren’t dumb to let you become a root user without checking if you are really supposed to get it> The command to open the sudoers list is given below.

sudo visudo

The sudoer’s list is actually a file named sudoers.tmp in etc. The file looks like this if you open it with visudo command. What you see if is sudoers.tmp opened in an editor named nano.


GNU nano 2.2.2                   File: /etc/sudoers.tmp

# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
 #

Defaults        env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL

# Allow members of group sudo to execute any command after they have
 # provided their password
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d

# Members of the admin group may gain root privileges
 %admin ALL=(ALL) ALL

^G Get Help      ^O WriteOut      ^R Read File     ^Y Prev Page     ^K Cut Text      ^C Cur Pos
^X Exit          ^J Justify       ^W Where Is      ^V Next Page     ^U UnCut Text    ^T To Spell

Notice line #19. Add a line like the one below just under line #19.


user    ALL=(ALL) ALL

Where user is the name of the user to whom you want to give root access.

Enjoy SUDOing 🙂

Linux Commands – File Operations


Command : cp <source> <destination>

What it does: Copies source file or directory to destination.

Command : mv <source> <destination>

What it does: Moves source file or directory to destination.

Command : rm <file>

What it does: Removes the file or directory.

Command : mkdir <dir>

What it does : Makes a directory named <dir>.

Command : rmdir <dir>

What it does: Removes <dir> if empty.

Example


bios@bios-mac-7:~$ cd ./Vishnu\ RKM/
bios@bios-mac-7:~/Vishnu RKM$ ls
error.png       plugin prob.odt        terminal_eror.png
lock error.png  suggested plugins.png
bios@bios-mac-7:~/Vishnu RKM$ mkdir backup
bios@bios-mac-7:~/Vishnu RKM$ ls
backup     lock error.png   suggested plugins.png
error.png  plugin prob.odt  terminal_eror.png
bios@bios-mac-7:~/Vishnu RKM$ cp plugin\ prob.odt ./backup/
bios@bios-mac-7:~/Vishnu RKM$ ls
backup     lock error.png   suggested plugins.png
error.png  plugin prob.odt  terminal_eror.png
bios@bios-mac-7:~/Vishnu RKM$ cd ./backup/
bios@bios-mac-7:~/Vishnu RKM/backup$ ls
plugin prob.odt
bios@bios-mac-7:~/Vishnu RKM/backup$ cd ./..
bios@bios-mac-7:~/Vishnu RKM$ rmdir backup/
rmdir: failed to remove `backup/': Directory not empty
bios@bios-mac-7:~/Vishnu RKM$ cd ./backup/
bios@bios-mac-7:~/Vishnu RKM/backup$ rm plugin\ prob.odt
bios@bios-mac-7:~/Vishnu RKM/backup$ ls
bios@bios-mac-7:~/Vishnu RKM/backup$ cd ./..
bios@bios-mac-7:~/Vishnu RKM$ rmdir backup/
bios@bios-mac-7:~/Vishnu RKM$ ls
error.png       plugin prob.odt        terminal_eror.png
lock error.png  suggested plugins.png
bios@bios-mac-7:~/Vishnu RKM$ mkdir pics
bios@bios-mac-7:~/Vishnu RKM$ cp *.png ./pics/
bios@bios-mac-7:~/Vishnu RKM$ rm *.png
bios@bios-mac-7:~/Vishnu RKM$ ls
pics  plugin prob.odt
bios@bios-mac-7:~/Vishnu RKM$ cd ./pics/
bios@bios-mac-7:~/Vishnu RKM/pics$ ls
error.png  lock error.png  suggested plugins.png  terminal_eror.png
bios@bios-mac-7:~/Vishnu RKM/pics$ cd ./..
bios@bios-mac-7:~/Vishnu RKM$ mkdir files
bios@bios-mac-7:~/Vishnu RKM$ ls
files  pics  plugin prob.odt
bios@bios-mac-7:~/Vishnu RKM$ mv plugin\ prob.odt ./files/
bios@bios-mac-7:~/Vishnu RKM$ ls
files  pics
bios@bios-mac-7:~/Vishnu RKM$ mkdir temp
bios@bios-mac-7:~/Vishnu RKM$ ls
files  pics  temp
bios@bios-mac-7:~/Vishnu RKM$ rmdir temp
bios@bios-mac-7:~/Vishnu RKM$ ls
files  pics