Isn't it intimidating to look at the linux (or unix) shell in the beginning? There's something powerful about the stream of texts that stream across the screen. As a nerd kid, we all grew up to see the mesmerizing visuals of green texts on black screen and wanted to be one of them.
As an engineer, I get to see that life every day. While many of you think of it as some lightsaber sort of weapon, to us the linux terminal is really all about convenience, speed and information.
Being able to use the linux terminal is crucial, but it doesn't magically turn you into a pro, what you do with the terminal does that.
Nevertheless, if you have to Google up most information to get around your computer, that doesn't help, right? So, if you just put in the effort to incorporate the below commands in your everyday linux usage (and by extension, computer usage), you'll no longer feel scared to pull up the terminal, rather, you'll start to see the terminal as your tool and be more productive.
pwd to traverse the filesystem
cd: this command is used to change the current working directory in a shell
~ $ cd Downloads ~/Downloads $
ls: this command is used for listing all the files and directories in the current directory.
ls -a will display all files including hidden files (that start with .)
ls -l will list all files in separate lines and show more information
ls -t will sort files by their modification time.
ls -lt will list files with information by their modification time
~ $ ls a.txt b.txt cat ~ $ ls -a . .. a.txt b.txt cat .hidden ~ $ ls -l -rwxr-xr-x 3 user user 4096 Jul 21 2019 a.txt -rwxr-xr-x 3 user user 4096 Jul 21 2019 b.txt drwxr-xr-x 3 user user 4096 Jul 21 2019 cat
pwd: this will display the current working directory you are in.
~ $ pwd /home/user
rmdir to perform basic file operations
cp: this will copy a file from the source to the destination.
cp -rif you add -r, then it will recursively copy all contents from a folder to the destination.
~ $ cp a.txt Downloads ~ $ cp -r cat Downloads ~ $ cd Downloads ~ Downloads $ ls a.txt cat
mv: this will move a file from the source to the destination, it accepts the same parameters as
cp so skipping the examples
rm: this will remove a file.
rm -r will recursively delete all files from the directory.
rm -rf will recursively delete all files and will force delete everything.
yum to install packages from the repository
Most linux distros will contain some sort of package management. And all of them contain a command-line utility that lets you install a package. Learning this tool is necessary.
On debain-based distros such as Ubuntu, Linux Mint, elementary Os etc, it is
apt-get (checkout point #2: apt-fast to accelerate your installs)
On arch-based distros such as Arch or Manjaro, it is
On Redhat/SUSE based distros such as fedora, centos or openSUSE, it is
cat to view a file and
nano to edit a file inside the terminal
If you want to print a text file on the terminal,
cat is your best friend regardless of your preference in pets.
~ $ cat a.txt this is the contents of a.txt file
On the other hand, if you want to edit a file, use
nano to edit the file. to use it, type
nano filename and your entire terminal will turn into a text editor. To save it press
Ctrl+O and to exit press
grepto search for text in a file
few tools are as deceptively simple as
grep. If you have a long file and need to search for text, just type
grep <query> filename. it will return all the lines that contain the string in query.
Now that you have a taste of
grep you need to learn more, adding -B4 will match the 4 previous lines and adding -C3 will print the 3 lines that follow the match.
Also grep can be piped. you can
cat file.txt | grep hey to search for all
This presents a fantastic use case, you can find your cpu model by typing
cat /proc/cpuinfo | grep "model name". This is just the tip of the
find to search for a file
if you remember parts of a file's name and don't remember the directory they are in, you can use
find to find the full path to the file.
In a recent incident, I forgot the folder I had the installer of jmeter. I had typed
locate jmeter and it presented me with an unfathomable number of paths that contained the word jmeter.
Since i knew it's a tarball, so I ran
locate jmeter | grep tar and it presented me with a single file containing the full path.
The difference between
locate is, find will search from your current directory, thus it's slow but accurate.
locate on the other hand has its database of all paths, which, by default, updates once a day. you can run
updatedb.mlocate to update the database manually
man to read manual for any command
If you want to know in-depth about all the options of
grep, we instinctively go to Google, but you don't have to leave the terminal,
man grep will open a detailed manual listing every feature of that command.
Yes. You can indeed type
man man to read the manual about manual. Thanks for asking.
Be aware though,
man pages can be quite boring and lengthy! Feminists will surely complain about
Bonus command #8:
less does a similar job of handling long outputs
cat a long file or run a command that outputs a lot of information, it will scroll up the scrieen quickly and may overflow the max lines of your terminal.
If you pipe the output to
cat longfile.txt | more you will be presented with information one screen at a time, and press
space to go to the next screen.
A better version of more is
less (in our modern, truly minimalist fashion), you can scroll lines up or down using arrow keys, and you can even search for text by pressing forward slash
/ followed by the search text and hit
Did it help overcoming the fear of terminal?
If yes, appreciate by sharing this with the social icons below (on the right side if on a computer)
I would advice you to keep using the terminal to get better at it. Practice is indeed useful.