Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

10 Tips on Working Fast in UNIX or Linux

DZone's Guide to

10 Tips on Working Fast in UNIX or Linux

These ten commands and other tips will increase your productivity by allowing you to navigate and accomplish tasks quicker in UNIX and Linux.

· Performance Zone ·
Free Resource

Maintain Application Performance with real-time monitoring and instrumentation for any application. Learn More!

Have you ever amazed to see someone working very fast in UNIX, firing commands and doing things quickly? Yes, I have seen that a couple of times and I have always inspired to learn from those superstar developers. In this article or tutorial or whatever you call it, I have dedicated to sharing some UNIX command practices I follow to work fast, quick, or efficiently in Linux. I work for Financial services industry and my work involves development and support of online stock and futures trading application in Electronic trading, Derivatives etc. All our services run on Linux servers so it's very important for me to work efficiently and quickly in 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.

10 UNIX and Linux Productivity Tips

If your server also resides in a Linux machine and your day 2-day work involves a lot of searching and playing around UNIX commands then these tips will save a lot of your time. Below tips are of my years of experience in UNIX which I have summarized as 10 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 my 30% time on average. It always happens that you fire same UNIX command multiple times within a fraction of seconds, before knowing this trick I used to use up and down arrow for finding my command and then executing them which takes some of my time but after knowing this trick I just have to remember the command name e.g. !ls will execute your last "ls -lrt" , !vim will open your last file without typing full command.

Use this tip and experience it, It definitely saves loads of time and it's also useful on shell 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).

2) 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 up and down arrow doesn't work like K shell and C shell. This is extremely useful if you are stopping or starting your server or Java application for debugging ging purpose frequently.

Btw, if you are not familiar with bash shell yet, I suggest you take a look at 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.

3) 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 "CRTL+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 percentage of repetition is quite high. for me

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

4) Using History Command to Get 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 of the cases, there is a certain command like starting, stopping, checking log files, making a build or doing release etc.

These are the commands you often need to execute and if you don't remember 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 variable e.g. HISTSIZE which defines how many command 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 appropriate Linux commands for the task at hand.

5) Using Regular Expression in grep and find

The grep and find are the two best tools UNIX provide to us. almost everybody needs to search something in UNIX e.g. a file, a directory, certain words in file e.g. ERROR or Exception and if you know how to use the grep and find with 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 command 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 this powerful Linux commands.

6) Using pipe Instead of Firing Two Commands

Just shown above this nice little tip I guess everybody knows.

7) Using Aliases and Defining Them in Bash Profile or 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 e.g. -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.

8) Using pushd, popd, cd -, ~ to Move Across a Directory

Based on my experience, navigation in UNIX shell takes almost 50% times of people and if you are going to write directory path every now and then just forget about working fast. so instead of typing full 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

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 on the foreground.

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?

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

Collect, analyze, and visualize performance data from mobile to mainframe with AutoPilot APM. Learn More!

Topics:
unix ,linux ,command line ,grep ,find ,regex ,performance ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}