How to Manage Files from the Linux Terminal
To use the Linux terminal like a pro, you’ll need to know the basics of managing files and navigating directories. True to the Unix philosophy, each command does one thing and does it well.
Midnight Commander, a full-featured file manager for the Linux terminal, acts as a powerful front end to all these commands.
ls – List Files
The ls command lists the files in a directory. By default, ls lists files in the current directory. You can also list files recursively — that is, list all files in directories inside the current directory — with ls -R. ls can also list files in another directory if you specify the directory. For example, ls /home will list all files in the /home directory.
cd – Change Directory
The cd command changes to another directory. For example, cd Desktop will take you to your Desktop directory if you’re starting from your home directory. You can also specify a full path to a directory, such as cd /usr/share to go to the /usr/share directory on the file system. cd .. will take you up a directory.
rm – Remove Files
The rm command removes files. Be careful with this command — rm doesn’t ask you for confirmation.
rmdir – Remove Directories
The rmdir command removes an empty directory. rmdir directory would delete the directory named “directory” in the current directory. rm -r directory would delete the directory named “directory” and all files in it.
mv – Move Files
The mv command moves a file to a new location. This is also the command you’ll use to rename files.
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.
mkdir – Make Directories
The mkdir command makes a new directory. mkdir example will make a directory with the name “example” in the current directory.
ln – Create Links
The ln command creates links. The most commonly used type of link is probably the symbolic link, which you can create with ln -s.
chmod – Change Permissions
chmod changes a file’s permissions. For example, chmod +x script.sh would add executable permissions to the file named script.sh in the current folder. chmod -x script.sh would remove executable permissions from that file.
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.
mc – A Full File Manager
Midnight Commander is one of many fully featured file managers you can use from the Linux terminal. It isn’t installed by default on most distributions; here’s the command you’ll need to install it on Ubuntu:
sudo apt-get install mc
You can also use the mouse in Midnight Commander if your terminal environment has mouse support.
Remember that you’ll need to run these commands with root permissions if you’re modifying a system directory. On Ubuntu, add sudo to the beginning of commands you want to run with root permissions