The command line can be an intimidating and scary black screen when first introduced to beginners. Where are the fancy buttons? The colors? How can I move files? Where is my mouse!?
These 5 Linux Commands will give you a better handle of the command line and will make you look like a pro.
cp command stands for "copy" and the syntax of the
cp command works like this:
$ cp [OPTIONS] SOURCE DESTINATION
SOURCE is copied over to
DESTINATION, you can also have multiple
SOURCE files, so that you can copy over multiple files to
DESTINATION. A useful flag that you may end up using a lot is the
--recursive command, which allows you to cp entire directories recursively. For example:
mv command otherwise known as "move" will move files wherever you want them to go, similar to the
cp command, but instead of leaving a copy the entire file or directory will get moved to the
DESTINATION. Also, in the
mv it shows,
mv - move (rename) files. So, not only can you move files, but by using the
mv command like this:
$ mv [FILE] [RENAMED]
A useful flag to understand what is going on while using the
mv command is the
-v command, which stands for verbose. When you use the
mv command, use a
-v before your
SOURCE input to show a more detailed view of what the
mv command is doing. For example:
| command, aka the "pipe" command is used to combine two or more commands where the first command will be an input for the second command. (And so on so forth) Seeing the "pipe" in action makes it easier to understand.
In this block of code, the contents of cat are shown, then you would use the
| command to use the contents of
file.txt and run the command
sort on them, which alphabetically sorts the contents of
file.txt and displays those results on the console.
The right-angle bracket is a way to transform and push data in your terminal from one place to another. Just like the example from the pipe command you can store the data of the sorted
file.txt to another file called
First, you sorted checked the file contents of
file.txt and then you used the
pipe command along with the
sort command. From above, you saw that this displayed the contents of
file.txt but alphabetically sorted, now with the
> command, you take those contents of the alphabetically sorted file and put that data into a new file called
sorted_file.txt. Neat right?
|may not be super useful by themselves, but when used with other commands they are very powerful tools that you can use to your advantage.
grep prints lines that match a pattern that you specify. The usage is as follows:
$ grep [OPTION...] PATTERNS [FILE...]
A simple usage for the
grep command could be to find all lines that have an "a" in a file. For example:
You can extend the
grep command to look for certain files, combining the
grep command with the
Using these commands in unison with each other will give you a better grasp at the Linux terminal, and make you look like a pro to your friends and co-workers.
tree command is not a preinstalled command available in Linux, although, it is a nifty tool that can help you find files in your system. To install
$ sudo apt install tree
For Ubuntu systems, although other systems may use different package managers.
tree lists contents of a directory in a tree-like format. For basic usage you could run
$ tree folder
$ tree labs | grep .cpp
Hope you found this useful!