Upload
rohit-kamalakar
View
74
Download
11
Tags:
Embed Size (px)
Citation preview
Login
Become a memberRSSPart of the TechTarget network
SearchEnterpriseLinux.com
News
Latest Headlines
Ubuntu offers cloudfreebie; openness ofAndroid examined:news in brief
Microsoft supportsRed Hat Linux in
Hyper-VIBM adaptsmainframe for
Linux, Red Hatbolsters Express:
News in brief
View All NewsEnterprise Linux
Topics
Topics
Enterprise Linux applications and databases
Open source databases, Open source Web and application servers, Enterprise applications for Linux
Linux administration issues
Linux administration tools, Linux management and configuration, Linux interoperability, Linux licensing and support,
Linux monitoring and troubleshooting, Introduction to Linux system administration
Linux enterprise desktops
Linux enterprise desktop distributions, Linux enterprise desktop applications
Linux in the data center
Cloud computing on Linux, Linux high-performance computing and supercomputing, Linux server hardware, Linux
virtualization, Linux backup and storage, Linux network administration, Open source projects in the cloud
Linux migration
Unix-to-Linux migration, Windows-to-Linux migration, Linux to Linux migration
Linux security
Linux security risks and threats, Linux system security best practices, Linux security tools
Linux server distributions
Linux news and updates, Red Hat Enterprise Linux Server, SUSE Linux Enterprise Server, Ubuntu Server,
Noncommercial Linux distributions, Oracle Enterprise Linux
Hot Topics
Enterprise applications for LinuxLinux administration tools
Linux virtualizationTutorials
Advice & Tutorials
A guide to becoming a Puppet master77 useful Linux commands and utilities
Open source virtualization digestA collection of the top Linux command tipsRed Hat gives Windows the boot with RHEV 3.0
Technology Dictionary
Find definitions and links to technical resources
Powered by WhatIs.comExpertAdvice
Tips
Process monitoring and management on Red Hat using graphical tools
Ten command line time-savers for Linux administratorsHow to install an OpenStack Nova compute cloud with PuppetView All Tips
Answers
Migrating infrastructure from Unix to LinuxInstalling Nagios on Linux and unravelling software code namesSystems monitoring and tuning tools for RHEL 5View All Answers
Ask a Question
Get help from our technical communityPowered by ITKnowledgeExchange.com
WhitePapers
Research Library
White PapersBusiness WebcastsDownloadsPowered by Bitpipe.com
Product Demos
Try out software demosPowered by 2020Software.com
Resource Centers
Red Hat Enterprise Virtualization Webinar SeriesView All Resource Centers
Blogs
Blogs
Enterprise LinuxLogI.T. Security andLinuxAdministration
Powered byITKnowledgeExchange.com
Search this site SEARCH Search
Home
TopicsLinux administration issuesIntroduction to Linux system administrationTen command line time-savers for Linux administrators
Ten command line time-savers for Linux administrators
Jason Gilmore, Contributor
E-mailPrintA
AAAAALinkedInFacebookTwitterShare ThisRSSReprints
Although the Linux desktop has been subject to enormous improvements over the past twenty years (with perhaps the most notable
change coming by way of the Ubuntu Unity interface), the command line remains unparalleled in terms of the power it can offer anexperienced system administrator. Although most of the following 10 tips focus on the Bash shell, all of these tips will be easily applicableto other modern shells.
1. Create and enter a directory using one commandCreating and subsequently entering a new directory is such a common task it seems that there should be a shortcut for executing both
commands in the shell. While it’s not, you can add the following function to your .bashrc file:
mkcd()
{
mkdir $1
cd $1
}
Then run source .bashrc to read the changes into memory, and complete both tasks using the mkcd command:
wjgilmore@ubuntu:~$ mkcd articles
wjgilmore@ubuntu:~/articles $
2. Return to the previous directoryWhen you need to move from a deeply embedded directory and want to return to the original directory you could pass the previous pathinto the cd command, but a little-known cd argument makes this trivial. This sequence demonstrates the behavior:
wjgilmore@ubuntu-laptop:~/Documents/techtarget_articles/ten_command_line_tricks/test2$ cd
wjgilmore@ubuntu-laptop:~$ cd -
~/Documents/techtarget_articles/ten_command_line_tricks/test2$
wjgilmore@ubuntu-laptop:~/Documents/techtarget_articles/ten_command_line_tricks/test2$
3. Creating directory bookmarksContinuing along with the theme of directory interaction, there are some directories that you will inevitably return to time and again. It'spossible to create bookmarks that allow you to quickly navigate to those directories by adding their paths to the $CDPATH shell variable(within your .bashrc file):
CDPATH='.:/home/wjgilmore/books'
Once added, you can navigate directly to the books directory from anywhere within the operating system path simply by executing thefollowing command:
$ cd books
4. Deftly edit the command lineHow many times have you tediously edited and executed a series of slightly dissimilar commands? Such as when building the PDFversion of various book chapters I'm working on from the Markdown source I regularly execute the following command:
$ pandoc -o html/chapter06.html chapters/chapter06.md --template=templates/html.template
In order to also build the chapter04.md source document command line novices would quickly tire of arrowing
Show Me More
undefined Submit
More on Introduction to Linux system administrationGet help from the communityPowered by ITKnowledgeExchange.com
up to retrieve the previously executed (above) command from history, and then arrowing left until replacing both instances ofchapter06.md with chapter04.md. There are several more efficient ways to perform this task. First, consider using Bash's command
line editing keyboard shortcuts (two modes are supported: Emacs and vi), which allow you to quickly navigate to the desired location:
Ctrl + a: Go to beginning of line
Ctrl + e: Go to end of line
Alt + f: Go forward one word
Alt + b: Go backward one word
A second and even more efficient approach involves using command line substitution. The following command will replace the 06 foundin the previously executed command with 04:
$ pandoc -o html/chapter06.html chapters/chapter06.md --template=templates/html.template
$ !!:gs/06/04
pandoc -o html/chapter04.html chapters/chapter04.md --template=templates/html.template
Incidentally if you're using the GNOME terminal then the meta (Alt) key won't work as described, because GNOME terminal alreadybinds the Alt key to toolbar commands. Alternatively you can use Shift + Alt as the meta key, but this is a bit awkward. Instead, if youdon't require the toolbar command shortcuts, disable them by navigating to Edit -> Keyboard Shortcuts... and disable the Enable menuaccess keys option.
5. Saving a long command for later useWhen working through a sequence of system administration operations, it is possible to type a particularly long command and then realizebefore executing it a step in the sequence has been left out. Rather than deleting the command, you can save it to the history withoutexecuting it by appending a hash mark (#) to the beginning of the command:
$ #this is some ridiculously long command that I want to save
After pressing the Enter button, arrow up and you'll see the command has been saved. To execute the command, just remove the hash
mark from the beginning of the line before execution.
6. Save typing using command aliasesThe ls command's long listing format (ls -l) can be frequently used, but the hyphen makes it a bit unwieldy when typing furiously. Youcan create command aliases of for longer commands using the alias command within .bashrc. In this example, the command alias diris substituted for ls -l:
alias dir='ls -l'
7. Saving more typing by ignoring typosYou're in the terminal zone, blazing from one directory to the next while copying, updating and removing files at will. Or you're not,because the fingers are moving faster than the brain or even keyboard response time can handle, causing you to constantly backtrack andcorrect your typos. Add the following line to your .bashrc file and the shell will automatically fix any typing blunders you make when
identifying file or path names.
shopt -s cdspell
8. Opening applications in the backgroundWhen cruising around the command line, you may need to do another task such as respond to an email. Of course, it's possible to openGUI applications from the terminal in the same way you'd execute any other command, done simply by invoking their name, in this case,opening Gimp:
$ gimp
But doing so effectively ends your terminal session, because the application will open in the foreground. If you're regularly opening aparticular application from the command-line, consider modifying its default invocation within your .bashrc file:
gimp()
{
command gimp "$@" &
}
Reload your .bashrc file (see the source command) and you'll be able to invoke the Gimp application, passing along the names of anyimage files you'd like to open, with the added bonus of retaining control of the terminal.
9. Do more with less
The more command is useful for quickly perusing the contents of a text file. Once the file is loaded into the page you can use the forwardslash (/) to search the file. The problem is that once you've found the desired string it's not possible to navigate up and inspect thecontents that appeared prior to this string. The less command doesn't suffer from this disadvantage, allowing you to scroll both up anddown within a text file. The less command is invoked in the same manner as more:
$ less sometextfile.txt
10. Clean up your command line historyThe history command is easily one of the most powerful tools at your disposal. But there is one timesaver in particular that deservesmention: the $HISTIGNORE shell variable.
Over time your history list will become incredibly long. Take advantage of the $HISTIGNORE ;variable to mute the recording of anycommands you deem irrelevant:
$ export $HISTIGNORE="&:cd:exit:ls"
This will cause all duplicate commands, and the cd, exit, and ls commands to be omitted from the history list.
Speed is key to mastering the command line, and these ten tips and tricks should get you started on your command line mastery. If youwould like to share any other tips, please contact me via my Web site.
ABOUT THE AUTHOR: Jason Gilmore is founder of the publishing, training, and consulting firm WJGilmore.com. He is theauthor of several popular books, including Easy PHP Websites with the Zend Framework, Easy PayPal with PHP, and BeginningPHP and MySQL, Fourth Edition. Follow him on Twitter at @wjgilmore.
Dig Deeper
People who read this also read...
A collection of the top Linux command tipsEnterprise Linux learning guide libraryFive Linux performance commands every admin should knowGuide to the Linux security toolboxThe top 10 Linux tips of 2010
Related tags
adminlinux
Related glossary terms
Terms for Whatis.com - the technology online dictionary
Hardy Heron (Ubuntu 8.04 LTS Server Edition)high-performance computing (HPC)Open Directory Project (ODP)copyleftLiveDistroYellowdog Updater, Modified (YUM)BSD (Berkeley Software Distribution)shellFree Software Foundation (FSF)Tcl/Tk (Tool Command Language)
Show memore
This was first published in July 2011
Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from otherenterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guaranteethe accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any
questions, answers, information or other materials received through this Web site is at your own risk.
Back to top
You May Also Be Interested In...
More Background
The top 10 Linux tips of 2010Enterprise Linux learning guide library
More Details
Take control of the command line with 'A Practical Guide to Linux'Expert Q&A: Simplifying configuration management with Puppet
2020software.com, trial software downloads for accounting software, ERP software, CRM software and Business Software Systems
News
Latest Headlines
Ubuntu offers cloudfreebie; openness ofAndroid examined:news in briefMicrosoft supportsRed Hat Linux in
Hyper-VIBM adaptsmainframe forLinux, Red Hat
bolsters Express:News in briefView All News
Enterprise LinuxTopics
Topics
Enterprise Linux applications and databases
Open source databases, Open source Web and application servers, Enterprise applications for Linux
Linux administration issues
Linux administration tools, Linux management and configuration, Linux interoperability, Linux licensing and support,Linux monitoring and troubleshooting, Introduction to Linux system administration
Linux enterprise desktops
Linux enterprise desktop distributions, Linux enterprise desktop applications
Linux in the data center
Cloud computing on Linux, Linux high-performance computing and supercomputing, Linux server hardware, Linuxvirtualization, Linux backup and storage, Linux network administration, Open source projects in the cloud
Linux migration
Unix-to-Linux migration, Windows-to-Linux migration, Linux to Linux migration
Linux security
Linux security risks and threats, Linux system security best practices, Linux security tools
Linux server distributions
Linux news and updates, Red Hat Enterprise Linux Server, SUSE Linux Enterprise Server, Ubuntu Server,Noncommercial Linux distributions, Oracle Enterprise Linux
Hot Topics
Enterprise applications for LinuxLinux administration toolsLinux virtualization
Tutorials
Advice & Tutorials
A guide to becoming a Puppet master77 useful Linux commands and utilitiesOpen source virtualization digestA collection of the top Linux command tipsRed Hat gives Windows the boot with RHEV 3.0
Technology Dictionary
Find definitions and links to technical resourcesPowered by WhatIs.com
ExpertAdvice
Tips
Process monitoring and management on Red Hat using graphical toolsTen command line time-savers for Linux administratorsHow to install an OpenStack Nova compute cloud with PuppetView All Tips
Answers
Migrating infrastructure from Unix to LinuxInstalling Nagios on Linux and unravelling software code namesSystems monitoring and tuning tools for RHEL 5View All Answers
Ask a Question
Get help from our technical communityPowered by ITKnowledgeExchange.com
WhitePapers
Research Library
White PapersBusiness WebcastsDownloadsPowered by Bitpipe.com
Product Demos
Try out software demosPowered by 2020Software.com
Resource Centers
Red Hat Enterprise Virtualization Webinar SeriesView All Resource Centers
Blogs
Blogs
Enterprise LinuxLogI.T. Security andLinuxAdministrationPowered by
ITKnowledgeExchange.com
Search this site SEARCH Search
More from Related TechTarget Sites
Data CenterServer VirtualizationCloud computingEnterprise Desktop
Data Center
Setting up Linux HA in the data center
Learning to set up a basic Linux HA cluster using Corosync and Pacemaker can help protect vital services in the event of ahardware failure.
Evaluating mainframe system monitoring tools
There are many system monitoring tools available for mainframes. This tip can help administrators analyze and choose thetool that best fits their needs.
Surprise! Data centers used less energy than expected
Data centers used less energy in the last five years than previously thought; and more data center facilities news in brief.
Server Virtualization
Shionogi breach spotlights virtualization security
A disgruntled ex-employee admitted to deleting VMs at the pharmaceutical company, highlighting the need for properenforcement of access-control policies in virtual environments.
Server consolidation project planning: Three steps to success
As the Boy Scouts always say: Be prepared. With a server consolidation project, you can prepare for consolidation in threedistinct phases.
Virtualization storage performance monitoring: Metrics and tools
Storage performance monitoring ensures that you’re warned of low storage capacity and that you’re up to date on
virtualization storage usage trends.
Cloud computing
Amazon cloud measures up to enterprise at last
Is AWS ready to take on the enterprise? According to the cloud computing Magic 8 Ball, "Signs point to yes."
Amazon GovCloud lurches toward private vs. public cloud
The U.S. government paid Amazon big bucks to build a private cloud, but some question how private it really is. And canany enterprise buy one?
Even the White House wants a cloud
It seems everyone wants a piece of the cloud lately, and the U.S. government has pulled together a team of cloud advisorsto assist them in figuring out how to best use the cloud.
Enterprise Desktop
The limitations of restoring files in Windows using Previous Versions
Microsoft's Previous Versions function can retrieve files, but only copies made during a system checkpoint or snapshot. Ourexpert found a third-party backup tool to span the gap.
Microsoft to roll out 'critical' patches for Windows and IE
Microsoft delivered updates to patch 22 vulnerabilities across several of its core products, including Windows Server 2008,Internet Explorer and the .Net Framework.
Eight ways Windows 8 and Kinect could revolutionize IT administration
Microsoft Kinect has obvious implications for gaming, but a rumored integration with Windows 8 could mean big things forthe future of IT.
All Rights Reserved, Copyright 2003 - 2011, TechTarget
About usContact usSite indexPrivacy policyAdvertisersBusiness partnersEventsMedia kitTechTarget corporate siteReprintsSite map