In this post let’s focus on 5 hands-on Linux command that increases your productivity. If you are new in Linux world may those commands makes more comfortable to work on the terminal in the early days.
- cd(change directory) + -(dash): This command takes you to in your last directory. See the example below:
#you are in system directory, then changed to
de@de:mosaiq@debian:/etc/systemd/system$ cd ~/var/log/apt#apt logs
de@de:/var/log/apt$ cd -#After hitting cd - you are back to your previous directory
2. sudo !! is also one of my favorite commands that allows you to perform previously command with sudo right.
Let’s say you are configuring some network stuff and want to move a configuration file to /etc directory as below:
de@de:~/codebase/medium$ mv networking /etc/
mv: cannot move ‘networking’ to ‘/etc/networking’: Permission denied#instead of typing the previous command with sudo,do simply as below
de@de:~/codebase/medium$ sudo !!
sudo mv networking /etc/
[sudo] password for de: ******** #enter my password
3. hostname -I give you IP address without full content of ip addr show or ifconfig(legacy).
# if you need only ip address, simply:
de@de:~$ hostname -I
4. alias save your time to type long commands. Especially,if you are working on cloud-native environment which increased remarkably last few years such as Docker, Kubernetes, AWS… UNIX-like environments. You need to run some long commands often. In those case, an alias is a perfect tool. See in the example:
#here I am running jenkins container on port 8080
$ docker run — rm -d -p 8080:8080 -v $(pwd):/var/jenkins_home my_jenkins
If you know docker, when you run a container you have to always type docker run — rm -d then other custom stuff. Let’s make an alias. The syntax to define an alias:
# I gave name as dr
de@de:~$ alias dr=’docker run — rm -d’#using my alias
de@de:~$ dr -p 8080:8080 -v $(pwd):/var/jenkins_home my_image
de@de:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
73ff8ea712fa jenkins/jenkins “/sbin/tini — /usr/…” 20 seconds ago Up 18 seconds 0.0.0.0:8080->8080/tcp, 50000/tcp nostalgic_perlman
To see your alias: run in terminal alias. To make them persistence then add them to the following file: .bash_alias
See how it looks on my machine
5. Ctrl+z → Job control — backgrounding, foreground
Let’s say you are editing a configuration file via vim and you’re not done, but have to perform another task, simply CTRL + Z then vim will run on background and the terminal is available to use it. Whenever you need to back to the configuration file type just: fg
fg = foreground
As you see above, while I editing interface file I just hit Ctrl+z and the jobs move to the background, I created a directory named test then type fg move your background process to the foreground.
I hope those commands help you to speed up your terminal usage :)