Thursday, August 24, 2023

10 Tips to work Faster in Linux Command Line and Bash Shell for IT Professionals

Hello guys, Have you ever been amazed to see someone working very fast in UNIX, firing commands, and doing things quickly? Yes, I have noticed that a couple of times, and I have always been inspired to learn from those superstar developers. I have shared a lot of content on Linux from the Developer's point of view, including 5 Free Linux Courses for Programmers, and in this article or tutorial or whatever you call it, I have dedicated myself to sharing some UNIX command practices I follow to work fast, quick, or efficiently in Linux. I work for the Financial services industry, and my work involves the development and support of online stock and futures trading applications in Electronic trading, Derivatives, etc. All our services run on Linux servers, so I need to work efficiently and quickly on the Linux machine, and that's how I have learned these productivity tips in Linux.

This article is in continuation of my earlier article Top 10 basic networking Commands in Unix and How does nslookup command work in Linux. If you have not read those, you can see if you find them interesting and useful. In this UNIX command tutorial, I am going to share my experience on how to work quick, fast, and efficiently in UNIX.

By the way, if you are new to Linux then I also suggest you go through a comprehensive Linux course to learn some basic commands and fundamentals like Linux file system, permissions, and other basic things. 

If you need an online course, I highly recommend Linux Mastery: Master the Linux Command Line in 11.5 Hours on Udemy. It's a very practical and hands-on course to learn Linux fundamentals in a quick time. It's also very affordable and you can buy in just $10 on Udemy flash sales which happen every now and then




10 UNIX and Linux Productivity Tips for IT Professionals

If your server also resides in a Linux machine and your day 2-day work involves a lot of searching and playing around with UNIX commands, then these tips will save a lot of your time. The below tips are of my years of experience in UNIX which I have summarized as 9 tips to work fast in UNIX :)

What I am looking forward is to get some more tips from you guys to enhance my arsenal, so please share how you work in UNIX, how you make most of powerful Linux commands and shell utilities provided by Linux and other UNIX operating systems like Fedora, Ubuntu, CentOS, etc.?

Please share your experience by posting comments to make this post useful and get most of it and benefit from each other's experience.





1. Use ! For executing the last command

This has saved me 30% time on average. It always happens that you fire the same UNIX command multiple times within a fraction of seconds, before knowing this trick I used to use the up and down arrows for finding my command and then executing them which takes some of my time.

After knowing this trick, I just have to remember the command name, like !ls will execute your last "ls -lrt" and !vim will open your last file in the VIM editor without typing the full command.

Use this tip and experience it, It definitely saves loads of time, and it's also useful on shells other than bash shell (like csh or ksh) where up and down arrow generally doesn't give you previous commands.

For example, After doing ls –l stocks.txt if you want to open stocks.txt you can use the vim editor as vi !$ (last argument)

UNIX and Linux Productivity Tips


2. Use "CTRL+R" for repeating the last matching command

Best out of the lot if you remember your last command executed sometime back and just want to find that command with the same argument and execute. This is the tip you need to remember.

Just press the "CTRL+R" and type words that you had in your last command, and UNIX will find that command for you then just press enter.

All the above three tips will save a lot of your time if you execute commands frequently, and the percentage of repetition is quite high. for me

I have saved almost 50-60% time by following the above three tips. Let me know how it works for you guys.




3. Use !! for executing the last command

This is the extension of the previous tip, which is used to execute the very last command you have executed. Since it just involves two keystrokes and that too for the same key, it’s amazingly fast.

This will also work on the shells in which the up and down arrow doesn't work like the K shell and C shell. This is extremely useful if you are stopping or starting your server or Java application for debugging purposes frequently.

Btw, if you are not familiar with bash shell yet, I suggest you take a look at the Bash Shell Scripting: Crash Course For Beginners, which will teach you the bash shell from the command line to shell

Script. A very useful course for anyone who wants to become a power user in Linux.

bash tips to work fast




4. Using history command for getting some of the most frequently used UNIX command

Well, this was the first tip I learned when I started working on UNIX :) This is your most helpful command in UNIX and Shell scripting. In most cases, there is a certain command like starting, stopping, checking log files, making a build or doing a release, etc.

These are the commands you often need to execute, and if you don't remember the exact command, no need to worry, just do history | grep "keyword" and you will get that command from the history on your Linux machine.

There are certain environment variables, like HISTSIZE, which defines how many commands UNIX history can store, so have it big.

Enough to save your time and avoid referencing your command booklet every now and then. Btw, if you are not familiar with basic Linux commands, then I strongly suggest you go through Linux Command Line Basics to get yourself familiar with commands like this. It will save you tons of your time by avoiding Google every now and then to search for appropriate Linux commands for the task at hand.

Linux command tips bash




5. Using regular expression in grep and find.

The grep and find are the two best tools UNIX provides to us. Almost everybody needs to search for something in UNIX, e.g. a file, a directory, certain words in the file, e.g. ERROR or Exception, and if you know how to use the grep and find with the regular expression, you will save a lot of your time by typing fewer commands.

For example, by knowing about egrep, you can fire egrep "ERROR|Exception" *.xml instead of firing two grep commands for finding ERROR and Exception individually.

If you are interested in learning more about grep and find command, then you should check out my earlier articles 10 examples of grep command, and 10 examples of find commands in Linux.

I have shared a lot of useful options for these two commands which will help you to get more from these powerful Linux commands.




6. Using pipe instead of firing two commands

Just shown above this nice and little tip, I guess everybody knows :)



7. Using aliases and defining them in the bash profile or the bashrc file.

Have you seen some strange commands working in someone's machine and not yours, which might be aliased he would have set up in either his .bashrc or .profile file?

Always do such kind of setup for commonly used command. There are lots of usage of the .bashrc and .profile file, but one of the most important ones is setting up aliases, e.g. "l." which finds all hidden files. "ls" which includes all useful option like -lrtH to show all relevant information.

You can further see Linux Command Line Interface (CLI) Fundamentals to learn more about how login works in Linux and what is the role of .login, .profile, and .bashrc files in Linux and bash shell.

Linux productivity tips



8. Using pushd, popd , cd - , ~ for moving across the directory.

Based on my experience, navigation in the UNIX shell takes almost 50% times of people, and if you are going to write a directory path every now and then just forget about working fast. So instead of full typing name, use all the above tips and make the best use of pushd, popd, cd - and cd ~ command. cd - is best if your switching between two directory location in UNIX.


9. Minimize the keystrokes or increase the speed of typing.

That I guess you know isn't it the less you type the faster you work to make use of your last typed command, make use of tab in bash, so that let the UNIX bash shell complete your command, use Ctrl+R if the last command you have typed is very long and you want to change just a few lines.



10.  Keep Learning new Linux commands

Try to learn more commands and their options and use this will reduce thinking the time for a particular task and use ctrl+z and fg and bg to suspend a process.

It saves almost 10% time if you are viewing multiple files or log files, so instead of every now and then executing vim commands, just do Ctrl+Z to suspend it and fg 1 or fg 2 to bring it into the foreground.

And if you are looking for some resources then you can check out Learn Linux in 5 Days and Level Up Your Career and follow Julia Evans on Twitter, she shares a lot of useful diagrams to remember essential Linux commands.



I hope these examples, tips on UNIX command will help you to do more in less time and enhance your productivity and experience while working in UNIX. This list is by no means complete, so please share how you working in UNIX, and of course, how fast are you working in UNIX?



Related UNIX Command Tutorials
  • 10 examples of date command in Linux (examples)
  • How to get an IP address from the hostname and vice-versa in Linux (command)
  • 10 examples of the xargs command in Linux (examples)
  • 5 Free Courses to learn Linux for Beginners (Free courses)
  • 10 examples of tar command in UNIX (examples)
  • 10 examples of Vim in UNIX (examples)
  • How to create, update and delete soft link in UNIX (command)
  • 5 examples of sort command in Linux (examples)
  • 6 Free Courses to learn Bash scripting in-depth (free courses)
  • 5 examples of kill command in Linux (examples)
  • 10 examples of chmod command in UNIX (examples)
  • 5 Best courses to learn Bash Scripting (courses)
  • 10 examples of lsof command in Linux (examples)
  • 10 examples of curl command in Linux (examples)
  • 10 examples of cut command in Linux (examples)
  • 10 Books every Linux Power user should read (books)
  • 10 Best Linux Courses for Programmers and Developers (Courses)

Thanks for reading this article so far. If you like this article, then please share it with your friends and colleagues. If you have any questions or feedback, then please drop a note.

P. S. - If you are new to Linux and looking for a free online training course to learn essential commands and concepts in Linux then I also suggest you check out Learn The Linux Command Line: Basic Commands course on Udemy. It's completely free and more than 50,000 students have enrolled in this course. All you need is a free Udemy account to join this course.

23 comments:

  1. $hexdump -C imagen2.jpg | grep " ff d9" :)))

    ReplyDelete
  2. good article. I learned some quick ways to increase my efficiency in unix. thanks Javin.

    ReplyDelete
  3. Thanks Anonymous, good to know that you find this Unix command tips useful for increasing productivity.

    ReplyDelete
  4. also we have alias command for storing cmd which we are using usaully. try with alias command that is more fun

    ReplyDelete
  5. Completely agree ashok, alias is another way of working fast in Unix, Even I have lots of alias in my .bashrc file for frequent commands, or changing directory or location etc.

    ReplyDelete
  6. Very useful tips Javin. One more tip I would like to add:

    While working in UNIX/LINUX environment some times you need to investigate an issue while server/application is writing log statements into log file. In that situation I found "less" command is very useful.

    less

    Above command opens the file in read only mode and good thing is all search command(All egrep command options work here) which work in vim editor/egrep options are also available in 'less'. But one advantage of using less over vim is as I mentioned while we investigate the issue, application might have written some more statements into log file. so to see those new statements just press ctrl + f will open the same file as if you are tailing the log so you can see most recent statments in log file. Again pressing ctrl + f will bring back us to less mode where we can continue our further investigation.

    In summary:

    less

    <>

    ctrl + f

    <>

    'ctrl+ f' will bring back us to less mode.

    Another variation of less is "less -I " will open the file in case insensitive mode where you can search not bothering about case while searching for words in you don't remember exact word.

    I use this tip almost everyday at my job and hope its useful for others too.

    --Suresh

    ReplyDelete
  7. another tips to working fast in Unix is use a bash script file to create shortcuts of frequently used unix command, directories and options.

    ReplyDelete
  8. Linux has lot of commands which makes easy for working on linux...
    typing vimtutor in terminal will show us lot of commands.

    ReplyDelete
  9. You are a star............

    thx
    ajay

    ReplyDelete
  10. One tips, which really helps me working with lots of UNIX boxes are storing logging information in Putty Connection Manager, it offers login macros, which can be really handy for storing username and password, especially if you have lot of servers to work on. From there, it just need one click to login and start working in UNIX shell.

    ReplyDelete
  11. I think you gave some of the best tricks that a person should utitlise and i am glad that i am doing most of them

    ReplyDelete
  12. It is wonderful article.. and very helpful!
    Thanks

    ReplyDelete
  13. @Priya, thanks you like this UNIX tips. Please share with your friends. Cheers ..

    ReplyDelete
  14. Very useful article.
    Just wanted to know, what does cd ~ do ?

    ReplyDelete
  15. cd - moves backwards and forwards (toggles) between two directories

    ReplyDelete
  16. @vidya, cd ~ takes you to home directory e.g /home/user , @unknown, yes cd - is a nice way to move between two directories, I use it a lot.

    ReplyDelete
  17. cd with no arguments does the same thing as cd ~

    ReplyDelete
  18. Something that I find very useful is shortcuts to move the cursor on the command line. For example, Ctrl+e moves to the end of the line, Ctrl+a moves to the start of the line. You can also cut the command line to the start of the prompt with Ctrl+u or just cut the last word with Ctrl+was. The best thing then is you can paste the cut text back with Ctrl+y. So you construct parts of commands into new ones very quickly.

    ReplyDelete
  19. Fine hints. Other great commends are find and locate, when you need to find where you have put that file...

    Anyway, I do not agree much about aliasing commands on a permanent basis (i.e. by setting the alias in .bashrc) . It may be dangerous because eventually it let you wrongly believe that a command has a certain standard behaviour. And make mistakes when do you log into another computer. In particular, never ever alias 'rm' to 'rm -i' !

    ReplyDelete
  20. Thank u very much for share these tips :D its good to remind some of them.

    ReplyDelete
  21. Don't forget the tab key to auto complete directory, command or service names. Example: service php[tab] restart (service php-fpm restart, or could be php5-fpm, etc), cat /var/lo[tab]/au[tab]/au[tab] (cat /var/log/auth/auth.log) - saves tons of tim

    ReplyDelete
  22. Great tios

    I use this often as well to know if server or process is running and to know it's details

    ps -elf | grep process

    ReplyDelete
  23. Thanks a lot! I did not know that pushd existed wow :D

    ReplyDelete