Administering or managing all types of files within the Linux OS is not complicated if you know the commands that you have at your disposal. Once you know how to navigate the terminal, you will be one step away from making all the modifications you want.
Thus, you will be able to copy, open, delete or edit them in a few steps. For this you will have to use the information that you will find in the following paragraphs of this article.
You will also find all the information related to the step by step that you must do to seamlessly manage Linux commands.
What should we take into account when managing Linux files?
To open the terminal in Linux you will need to press the key combination Ctrl + Alt + T. Keep in mind that everything you see inside this terminal is seen as a file, including the connected physical elements. On the other hand, if you are a newbie to Linux remember that the OS interprets lowercase and uppercase differently. So that, when writing the title of the files this writing must be as exact as possible. Not forgetting to correctly space with bars, periods and quotes.
Another aspect that you should keep in mind is that directories (files that order other files or directories) start from a base directory or “root”, as it is also known. The latter will always be symbolized with a bar /. If you do not want complications when operating, the easiest thing is to enable the “root” user. This represents the home directory of the administrator of the entire system. You will visualize it with a hash or numeral # being very useful to avoid several limitations.
What are the main commands used in file and directory management in Linux?
The main commands that you will have to use to work with files and directories in Linux are:
- exit: this is a very used and useful command because it helps you exit the user you are using.
- touch: using this application you can generate a file or file from scratch, completely empty.
- ls: a basic resource to list the files within the container file or directory in which it is located.
- cat: you will be able to use this command when you want to open the content of a file. It is also widely used and easy to implement.
- cp: this command is used to duplicate files as many times as you need and in the direction you want. To make it easier to remember, it comes from English “Copy”.
- mv: In the case that you do not need to copy a file, but change it, you will have to use this argument. In addition, it is valid to modify the title of the files.
- mkdir: helps to form or generate a new directory, or a set of these, from the current location.
- pwd: shows the full path that has taken you to the directory where you are at the time of use.
- clear: means clean in English and it is what it executes, an entire terminal cleaning leaving it empty for new commands.
- sherd: ends forever with a file or file that you want to remove from the OS. It acts very similar to
- rmdir: used to make blank directories that do not have any content disappear. This works contrary to rm or sherd that exterminates files or entire directories.
- more or less: with this command you will be able to view without altering the content of a certain file.
- Ln: thanks to this argument you will be able to generate hard links or symbolic links of the files. Thus producing labels for a certain file.
- Help: this is a very good tool that shows you a simplified list of all the commands that you can execute in the terminal.
Learn step by step how to perfectly manage files in Linux
We will show you below the step by step you have to do to manage the files in Linux:
View Files within a directory
You must follow this guide:
- Once you have open the terminal, an appropriate way to view all files within a directory or folder is with ls, preceded by the exact name of the directory. For example, / mydocuments ls.
- Such command will list the internal files one by one
- And if you want to see the files of the directory where you are currently put ls -lh.
- But if you need to view hidden files, use ls -a.
To delete files you will have to do this step by step:
- If you only need to remove a file inside the directory, you will have to enter it.
- Then you will have to establish The ubication, that is, in which directory it is. Then, you must write the file title divided like this example: rm / mydocuments /my.example.
You must bear in mind that rm –r delete all files and directories repeatedly and indefinitely and that the argument rm –f or rm –fr kill files and directories without confirmation. Therefore, these last methods should only be used when you are completely sure, otherwise you will lose all the information.
Edit files (cat or nano)
To carry out this task, you will have to consider the following:
- The argument cat it has a multiple use of editing, from merging to creating new files. For example, if you want to generate a new file and then edit the text, you will have to use cat next to the file’s title. An example of this would be: cat example.de
- Next, you will have to continue writing in the other lines by pressing Enter every time and when you want to finish, you will have to press Ctrl + D.
In the case of a more complete text file editor you can use elder brother and then the file name. For example, nano example.de
When you want to change directory in Linux, you will have to follow this guide:
- Write the command CD.
- Next to CD you must place a bar /, then he current directory where are you, another bar / and the new directory to which you want to scroll. Resulting in the command cd / mydocuments / newdocuments
If you use cd. . you will move to the top directory, if it exists, and with cd – the program will redirect you to the previous directory. You can also just use cd / to locate you in the root directory.
If what you want is to delete a directory, you will have to proceed like this:
- Place rmdir continuing with the writing of the title of the directory you want to delete. In this way it will be rmdir documents to delete.
- In this way will discard blank directories forever that you do not require
Like other delete commands, the rmdir does not ask for request to be executed, so you must make sure before deleting a directory.
Delete files within a file
In case you need to delete one or more files within a folder, you will have to do the following:
- The safest way to delete a file is by means of the This command overwrites it up to 25 times and can completely alter the content. If you write sherd -or you will delete entire files without the possibility of restoring them, something similar to rm, but more effective.
- Therefore, you must write sherd -or plus the name of the corresponding file. This will look like this: sherd -u / mydocuments or sherd –u / mydocuments / example.de.
- Another command you can use is sherd -fuz followed by the filename to enhance deletion. If you need help, you will have to write sherd help.
Create new file
When you need to create a new file, follow this step by step:
- As the objective is to generate a new blank file from the current location, you will have to use the command touch. For this, you will have to write it followed by the name you need to give the new file, eg: touch example.de
- Keep in mind that it works the same way to modify the time and date. In this case you will have to enter touch –t followed by the date and time (month, day, year, hour and minute together) and title of the file, so you will have touch –t 073020201640 example.de.
Create new directory
To create a new directory, do the following:
- Just use the command mkdir, remembering that you must place the directory in which you are. Then, you will have to enter the bar and the name of the new directory you want to create. An example of this is mkrdir / mydocuments / examplenewdocument.
- You can also generate an entire directory tree using the option mkdir -p.
- Also, with the alternative mkdirhier you will be able to establish a defined hierarchy in the directories.
Copy files and directories
When you need to copy files and directories, follow the steps that we show you below:
- To duplicate an original file in a destination file, you will have to write cp, then you will have to place the source directory, the file title, the destination directory and finally the file title. For example, cp /mydocuments/example.de/newdocuments/example.de.
But if what you want is to copy the entire directory completely, you can use cp -r.
View content of a file
If what you need is to see the content of a file, pay attention to this guide:
- When you enter cat you will be able to see the content of a file in simple terms, but its data cannot be paginated or modified.
- If you place cat followed by the title of an existing file cat example.de you will make the entire screen print.
- Instead, if you use the argument more or less, you will have a more optimal visualization, paginated and with the function of going back and forth. For this, you will have to write more or less before the file title. It will look like this: more example.de or less example.de.
If you have any questions, leave them in the comments, we will answer you as soon as possible, and it will also be of great help to more members of the community. Thank you! 😉