File management in linux.

Pv

 



In this blog you are going to see concept of file management and some of the linux commands which are used for file management. File management in linux is a very important topic.

There is a very popular statement on files – ‘Everything is a file in Linux’.



If you want to work with linux, you must know the concepts of file management in linux. All the command in this blog are easy to learn and understand. Now let’s take a look at the different types of files in linux -

1. Regular Files – all the common files you see on a linux desktop are termed as regular files. Human readable files like text files, program instructions,pdf files,image, music, video files, etc. are all comes under regular files.

2. Special Files – files that represent mounted devices like CD drivers, printers, storage devices, input and output devices are known as special files.

3. Directories – a file that stores regular and special files in a hierarchical order starting from the root directory. Directories is known as folders in windows OS.



We have learnt all three types of files in linux. Now let’s see some commands in linux for file management.



pwd

pwd command is used to find the location where you are working. If you open terminal and run pwd command, you will see - /home/user-name. This is because when you login to a linux machine you are dropped in its home directory.



cd

cd command is used to change directory or to navigate through directories. If you want to go in the “Downloads” directory we change directory by typing – cd Downloads

And if we want to go in our home directory we can go by just typing cd.



ls

If you are working in the terminal in a linux machine and you want to list all the files and directories on that location what would you do? You should use the ls command. ls command will list all the directories and files. In my linux machine, running ls command gives me -

Downloads Public VirtualBox Vms Templates

Desktop Music rtl8188fu Videos

Documents Pictures



ls -l

If we want to get detailed info about files we should use ls -l command. -l is a flag which we are using with ls command. Some detail which we got from this command -

drwxr-xr-x 2 why why 4096 Aug 28 15:27 Desktop

drwxr-xr-x 7 why why 4096 Aug 19 17:15 Documents

drwxr-xr-x 2 why why 4096 Aug 7 11:20 Downloads

drwxr-xr-x 2 why why 4096 Jul 5 14:07 Music

drwxr-xr-x 3 why why 4096 Aug 4 16:45 Pictures

drwxr-xr-x 2 why why 4096 Jul 5 14:07 Public

drwxr-xr-x 2 why why 4096 Jul 5 14:07 Templates

Detail which we got ls -l command seems quite unusual. If the line starts with “d”, it is a directory and if it starts with a “–“, it is a file. Each column shows name, modification date, number of hard links, owner, item size, group owner.



ls -a

Here we are using -a flag. This command list all files, including hidden files and directories. There are many hidden files in a linux system. If we only use ls command it will list only visible files and directories but when you use -a flag, it will list all files and directories. Running ls -a command -

.bash_logout .icons .tld_set

.bashrc .java .var

.cache .linuxmint Videos

.cert .local .viminfo

.cinnamon .minecraft 'VirtualBox VMs'

.config .mozilla .vscode

Desktop Music



touch

touch command can create an empty file with the name provided. If someone wants to create an empty file in a linux machine he would use touch command. Creating an empty file with touch command is very simple. We can create a file by typing – touch filename.txt

After creating a file with touch command we can see view it with ls.



mv

mv command can be used in many ways. It can rename a file or it can move a command from one location to another. We can move the file which we had previously created by the name filename.txt. We can move it by typing – mv filename.txt Documents/pfiles To move back that file to our home directory we can type – mv Documents/pfiles/filename.txt To rename a file we can type – mv filename.txt newfile.txt



cp

cp command is used to make a new copy of the original file. If we want to copy a file from Documents/pfiles we can type – cp newfile.txt Documents/pfiles



rm

If you want to delete a file you can use rm command. You have to type – rm newfile.txt



All these are the basic command which you should know if you are working in the linux terminal. That’s it for this blog.

Tags

Post a Comment

0Comments

Please Select Embedded Mode To show the Comment System.*