11 Commands You Need to Know to Manage Files from the Linux Terminal
Linux terminal is an awesome place to be and to use it like a pro, you’ll need to learn file system and management basics. As per the Unix philosophy, each command does only one thing and does it well.
Midnight Commander, a full-featured file manager for the Linux terminal, is a powerful front end to all these commands.
ls – list Files
The ls command list all files and folders in the current directory.
You can also list files recursively — that is, list all files in all directories inside the current directory — with ls -R.
ls can also list files in some other other directory if you specify the directory path. For example, ls /var will list all files in the /var directory.
cd – Change Directory
The cd command changes current directory to another directory we specify by path. For example, cd Downloads will take us to our Downloads directory if we’re starting from our home directory.
We can also specify a full or the absolute path to a directory, such as cd /var/lib to go to the /var/lib directory on the file system.
cd .. will take you one directory up.
rm – Remove Files
The rm command removes/deletes files. Be cautioned with this command — rm doesn’t ask for a confirmation.
For example, rm file would delete the file named “file” in the current directory. Just like with other commands, we can also specify a full or the absolute path to a file: rm /path/to/file would delete the file at /path/to/file on the file system.
rmdir – Remove Directories
The rmdir command removes an empty directory or a folder. rmdir something would delete the directory named “something” in the current directory. It is important to note that this command will only delete the directory if it is empty.
If the directory is not empty, we can use a recursive rm command to remove the directory and all present files. rm -r something would delete the directory named “something” and all files in it. This is a dangerous command that could easily delete a lot of important files, so be careful when using it. It won’t ask for confirmation.
Clearly, the command did not deleted the directory as it wasn’t empty.
mv – Move Files
The mv command moves a file to another location we specify. This is the same command we can use to rename files. For example, mv file newfile would take the file named “file” in the current directory and move it to the file named “newfile” in the current directory — renaming it, in other words.
In above sample, “ReactDemo” directory was renamed to “ReactHello”. Just like other commands, we can include absolute paths to move files to or from other directories.
cp – Copy Files
The cp command works the same way as the mv command, except it copies the original files instead of moving them.
You can also do a recursive copy with cp -r. This copies a directory and all files inside it to a new location. For example, the following command places a copy of the /home/avoiderrors/Downloads directory into the /home/avoiderrors directory:
cp -r /home/avoiderrors/Downloads /home/avoiderrors
touch – Create Empty Files
The touch command creates an empty file. For example, touch example creates an empty file named “example” in the current directory.
mkdir – Make Directories
The mkdir command makes a new directory. mkdir example will make a directory with the name “example” in the current directory.
As shown in sample, mkdir created another directory called AvoidErrors in it.