As a developer, you’ll need to be comfortable navigating around the Linux file system. After opening up a terminal multiplexer like Terminator, you’ll be dropped into the file system. You can use the pwd (Print Working Directory) command to see where you are. From your current location, you can move anywhere else with the cd (Change Directory) command. For example:
meanii √ cd ~/.ssh/
In the above example the tilde (~) represents your user’s home directory. If you’re inside a sub-directory and want to go up a level, you can do so with .., for example:
meanii √ cd ../Documents
Many Linux beginners don’t realize that you can also use the tab key to auto-complete file and directory names.
To quickly create a file you can use the touch
command.
meanii √ touch hello.txt
To copy a file or directory, use the cp command. In example below, the left-most file is the original file, and the right-most file is the copy to be created.
meanii √ cp hello.txt ciao.txt
Perhaps you made a mistake when naming your copied file and want to rename it. You can do this with the mv (Move) command. You can also use the mv command to move a file from one directory to another.
The below invocation of mv will rename the file hello.txt
to bonjour.txt
.
meanii √ mv hello.txt bonjour.txt
Let’s say the creation of ciao.txt was a mistake. We can delete it with the rm (Remove) command.
meanii √ rm ciao.txt
If we want to delete a directory and everything in it, you can pass the -rf
flag to rm. -f
will remove the files without confirmation, and -r
will remove files inside the directory. Note: be careful with this command. Make sure you are not deleting something important.
meanii √ rm -rf ~/Downloads
Let’s hold up a second. The Linux command line doesn’t show you what’s inside a particular directory unless you ask it to. It’s tough to be productive if you can’t see what you’re working with. This is where the ls command comes in useful
meanii √ ls ~/Downloads
ls
(List Files) allows you to see the filenames of any files in the given directory. If the command is run without an argument it will default to the current directory, but you can also specify a path on the right-hand side, as seen in the above example. ls is the simplest form of this command, listing only filenames. Often, you’ll want to see more information about the files you’re interested in. You may also want to see hidden files, which sometimes hold important configuration.
The ls -l
command allows you to see a more detailed view of each file. It’s so commonly used that ll is an alias that does the same thing. If you want to see hidden files as well, use ll -a
or ls -la
.
The ‘long list’ (-l
) version of the ls command will show you the following information about each file you are inspecting:
- File owner
- File group
- File size
- Modification time
- Filename
With these few commands, you should be able to comfortably move around the Linux file system, and create, move and delete files.