Linux Commands

Today I was lucky enought to be contacted for mentorship from a good guy from around the globe named Rizuan that happens to be studying the same that I did many years ago (Telecommunications Engineer), now I mostly a programmer of software developer that was my real passion without knowing it until I knew. Right now Rizuan is interested in several topics that I have some knowledge. I´m writting this text specially for him and to any one that might be of help. I was lucky enough to have a good mentor (Hector "cacho" Gonzalez) specially on this topic that I´m going to write about. Let's begin!

Basic Commands

The basic commands for moving around in the CLI are very basic that I just will name them for reference with some basic explanation:

ls     # list directory contents.
cd     # change directory.
pwd    # return working directory name.
cp     # copy files.
mv     # move files.
rm     # remove the non-directory type files.
mkdir  # make directories.
rmdir  # remove directories.
cat    # concatenate and print files.
more   # file perusal filter for crt viewing.
less   # similar to more.
tar    # creates and manipulates streaming archive file.
gzip   # compresses and decompresses files using Lempel-Ziv coding.

Other commands to learn: tail, head, ssh, scp, echo.

Let's not forget that we can learn all the specifics about how to use them with the mancommand which display the on-line manual pages.

Learning to discover new commands.

A very useful command is which that shows you here the binary location or what command is executing, for example:

which ls 
> /bin/ls
which less 
> /usr/less
which tree 
> /usr/local/bin/tree

As we can see on these examples the binaries are by convention located at a bin directory. I suggest you explore these directories to learn about new commands like the tree that I just show you. You can use man tree to learn what is for and how to use it.

Alias

As you will learn all the commands have many options that you can use to obtain diferent results or make different actions, let me give you an example:

ls -l # List in long format. A total sum for all the file sizes is output on a line before the long listing.
ls -A # List all entries except for . and ..
ls -G # Enable colorized output.

When you are working on your workstation or probably in a remote server you want do every tasks as fast as you think, thats why is important to be able to move around fast and know your tools alias is one of your best friends you can create your own commands based on your own taste. Let me show you some of the aliases that I use the most.

alias ls='ls -Gh'
alias ll='ls -la'
alias h='history'
alias ip='curl https://diagnostic.opendns.com/myip ; echo'

Tips about moving around

Shortcuts

clear

Probably you already know about the clear command you could create an alias like this alias c='clear' or probably you could use the shortcut ctrl+l which will clean the screen.

Go back to the previous directory or use the last argument.

You often will be in the situation that you are doing your stuff and move from one directory to another and want to go back, in this situation you might go back to your home directory or the previous one. Let me show you a situation:

cd /etc/apache2
pwd
> /etc/apache2
# then you want to go to your home directory where you have something that you want to take a look.
cd # same as cd ~
pwd
> /home/user
# If you want to go back
cd -
pwd
> /etc/apache2

Home Directory

A special mention to the ~ character that is the same as your home directory. You can always point to your home directory using ~ for example:

cp myscript.sh ~/bin
cd ~

Other useful commands

# grep, egrep utility searches any given input files, selecting lines that match one or more patterns.
#Example:
pwd
> /var/log
grep -i ERROR *
> wifi.log:Sun Jun  7 15:09:07.054 <airportd[273]> ERROR: rapportd (382) is not entitled for com.apple.wifi.join_history, will not allow request

Victor Yoalli

This is me.