LFCS and LFCE: How to create, move, delete and copy files and directories


This is another post towards the preparation for the Linux Foundation LFCS or LFCE exam. Where we are going to see "How to create, move, delete, copy files and directories.

The basic way to create a file is to use the touch command, which creates an empty file with a given name. 

touch testfile

And then the command ls to see if the file was created. 

ls

The files that we can see here, are inside our home folder or home directory. (it is by default where our terminal window opens up).

If you wish to check in which directory are you currently working it will be enough to type

pwd

In case you are missing the directory Documents it will be enough to type this command to create a new one:

mkdir Documents

Now we come back to our home directory and we create other test files to play with it. 

cd Documents
touch testfile1 testfile2 testfile3



Now we can check again if these files were created with the command ls -l.

ls -l



So after that, we can try to copy a file into the Documents folder with the cp command. 

command (file that we wish to copy) (the directory where we want to copy the file into it)

cp testfile Documents

It is also possible to copy multiple files at the same time.

(But be aware that this command can copy and replace files with the same name into the destination directory)

cp testfile testfile1 testfile2 testfile3 Documents



For the next step, we are going to try to move files into different directories. To do so we are going to use the mv command. It can also be used to rename a file if the destination directory is the same as where the file belongs. 

mv testfile testfile4
ls -l



We proceed using the command mv to move the testfile4 from his directory to the Documents directory.

mv testfile4 Documents
ls -l
ls -l Documents



Time to try to remove some files, we can do that with the command rm. 

ls -l
rm testfile2

Important: When we remove a file from the command line, is gone. There is not a trash bin or trash can like in other OS. 


Comments

Leave as a comment:

Archive