Linux - Basic and Daily Commands
Hello folks!
Today I want to share some commands for who is starting or for who forgot some commands that could be useful in day-to-day. I won't give a detailed explanation of each command, only a basic usage of each one, a short description and sometimes tips.
I started to use Linux at Indústria Fox (place that I still working) in the beginning of 2013 when Fabio Alvaro (Linux master, my boss and teacher. See more about him at: http://fabioalvaro.blogspot.com.br/) "Wololoed" me to install Slakcware (Yeah, Rambo mode ON) in my machine. The first few days were horrible but exciting. Nowadays I still using Slackware but I also work with Debian.
Very well, let's start the list...
* the commands starting with $ means that you can do with normal users. # needs super user permission. But you will not put it to execute the commands, it's only a reference.
$ pwd
It will show to you your current path.
$ cd path
Move you to the specified path. If your path start with "/" it means that you are giving the full path that you want to go, otherwise means that you are entering in directories directly from where you are.
Tips: cd ~ will move you to the user home; cd / moves you to root directory of Linux; cd .. return one path level.
$ mv origin destiny (root needed depending of origin or destiny)
Move the origin file to destiny directory. If you are moving a directory with items inside, use -R (recursive) on the final of the command.
$ cp origin destiny (root needed depending of origin or destiny)
Copy the origin file to destiny directory. If you are copying a directory with items inside, use -R (recursive) on the final of the command.
$ rm path1 ... pathN (root needed depending of the file permission)
Remove 1 or N files specified. If you are deleting a directory, use -R (recursive) on the final of the command.
$ ssh user@host
Access via SSH (Secure Shell) the determined host with determined user.
$ scp path user@host:path
Copy file between two machines via SSH: local to host, host to local, host to host. The example above is a transfer between the machine where you are logged in and an external host. Other examples: scp user@host:path path or scp user@host:path user@host:path. If you are copying a directory with items inside, use -R (recursive) on the final of the command.
# ifconfig
Show the informations about your network adapters (Ethernet, WiFi...).
$ cat path
Show the content of specified file.
$ vi path
The main text editor for Unix systems. Some Linux distros come with vim, a better version of vi. It's a little bit different from other text editors, you need to edit with some commands and it's really hard for those who are used to work with another simpler editor.
$ nano path
Another text editor for Terminal but it's too much easier.
$ find -option description
Search from where you are for files containing the description value in the respective option informed. For example: find -name test.txt the command will list the path of all files from where I'm and it subfolders which the file name is test.txt. If you know only a piece of the filename, you could make a search like find -name te*.txt. For more options and tips, here is a guide: 10 Tips for Using GNU Find.
$ df
Show the amount of avaliable disk space on wich the user has reading access in block. If you aren't a Jedi or a robot then you should use the option -a to see the space in KB/MB/GB instead of blocks (df -a).
# halt
or
# poweroff
Turn off the machine immediately. You can use the option -f to force this, but it's dangerous (The finishing of the processes isn't waited and it could result in memory's data problems). If you want to run this command with other user, this user needs to be part of power group.
# reboot
Similar to halt or poweroff but the machine will boot again after turned off.
# shutdown
Similar to halt or poweroff but it's safer. All logged users will receive a message about the shutdown and if another user log in, the command is canceled.
$ uname -a
Show basic system infos like distro name and version for example.
$ history
Show the list of commands sent to Terminal of current user.
$ su
Give super user permission while the session is opened. To exit from super user mode just type exit. Root's password required.
$ sudo next_command
Command available for sudoer users that allow execute the following command as root. Root password required.
$ mkdir dir_name
Create specified directory if the user has write permission in the parent path.
# chmod permission_code path
Give the specified permission to the following path. To know what permission you should give, you need to know two things: the kinds of permission, their values and what means each block that you give permission (usually three).
Very there are three kinds of permission:
read (r) - 4
write (w) - 2
execute (x) - 1
If you use the command ln -l you can see the actual files permission (something like -rwxr--r-- or -rwxrwxrwx). If you pay attention, you could see that we can separate in three groups after the first -111222333, where the the first one is the permissions assigned to the file owner, the second is for the group and the last for the public. For example, if the permission is -rwxr--r-- it means that the owner can read, write and execute this file and other group's members and the public can only read it. So, to give this permission for some file you just need to give execute the command chmod 744 path... But why 744? Each number position represents their respective group. The number 7 (The sum of read, write and execute values) will gives all permissions for the file owner and the number 4 only allows the groups member and the public read it.
# chown user path
Change the owner of the path passed as parameter for the respective user.
$ ln path link_path
Create a hard link of the informed path in the link path. If you user ln -s instead of only ln a symbolic link will be created. The difference between hard and symbolic link is that the hard link is a pointer to a file while the symbolic is a pointer to the specified path. It means you can rename or move the file and the hard link will still point it but if you change the file for new version, the link loses the reference and with symbolic solves this problem, but if you change the file path or rename it, you lost the reference.
$ tar options path
Tar files manager. You can extract, compact and do a lot of other things with tar files using this command. To extract a tar file you should use the option -xvf (x: extract; v: verbose (show the process progress); f: inform that the next param is file name of the archive) and inform the target file path. To compact, use -cvf (c: compact), the file to be generated and after you can inform 1 or N files to compact. To list: -tvf (t: list (? ... I don't know what's the link between t and list) and the target file.
$ cal
Show a beautiful and simple calendar.
$ date
Show the system date and time. There is a lot of options that you can use, type date --help to see.
$ mount path_to_mount path_where
Include some file system (Every file system that isn't a part of the Linux file tree, the /) into somewhere inside Linux file tree. There are some options that you can inform before specify the path_to_mount and the two most important are -t, where you can define the mount type like vfat for example, and -a, but in this case you don't pass the paths, only call for mount -a and all mounts specified at /etc/fstab will be mounted or remounted.
$ umount mounted_path
Manually unmount the specified file system.
$ ping host
Test TCP/IP connections between devices. You can use some options before the host like -c N, which will stop the ping process after N pings.
$ top
Show informations like memory and cpu usage and tasks.
$ kill process_id
Kill the process with the specified id (PID) if the invoke user has permission. You can get the PID using top command.
$ killall process_name
Kill all process with the specified that the current user has permission.
# useradd options user
Create an user. The's a lot of available option such as groups, bash file, etc. To see more about it, please visit The Complete Guide to “useradd” Command in Linux – 15 Practical Examples.
$ passwd
Change the password of some user. If you don't pass a parameter the command will understand that you want to change the password of the current user but you can specify the user if you have the permission to do this or if you are logged as root.
$ clear
Clear the terminal screen.
That's all! If you have some question, please, leave a comment so I'll replay as soon as possible!
Congratulations again for the blog , Pedro!
ResponderExcluirI liked the new layout \o/
I hope to see more posts about Android Development
Thank you, bro ;)
ExcluirI will post more about Android development as soon as possible!