Você está na página 1de 12

Login Become a member RSS Part of the TechTarget network SearchEnterpriseLinux.

com News
Latest Headlines

Ubuntu offers cloud freebie; openness of Android examined: news in brief Microsoft supports Red Hat Linux in Hyper-V IBM adapts mainframe for Linux, Red Hat bolsters Express: News in brief View All News Enterprise Linux Topics
Topics
Ente rprise Linux applications and database s

Open source databases, Open source Web and application servers, Enterprise applications for Linux
Linux administration issue s

Linux administration tools, Linux management and configuration, Linux interoperability, Linux licensing and support, Linux monitoring and troubleshooting, Introduction to Linux system administration
Linux e nte rprise de sktops

Linux enterprise desktop distributions, Linux enterprise desktop applications


Linux in the data ce nte r

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 se curity

Linux security risks and threats, Linux system security best practices, Linux security tools

Linux se rve r 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 Linux Linux administration tools Linux virtualization Tutorials
Advice & Tutorials

A guide to becoming a Puppet master 77 useful Linux commands and utilities Open source virtualization digest A collection of the top Linux command tips Red Hat gives Windows the boot with RHEV 3.0
Technology Dictionary

Find definitions and links to technical resources Powered by WhatIs.com Expert Advice
Tips

Process monitoring and management on Red Hat using graphical tools Ten command line time-savers for Linux administrators How to install an OpenStack Nova compute cloud with Puppet View All Tips
Answers

Migrating infrastructure from Unix to Linux Installing Nagios on Linux and unravelling software code names Systems monitoring and tuning tools for RHEL 5 View All Answers
Ask a Question

Get help from our technical community Powered by ITKnowledgeExchange.com White Papers
Research Library

White Papers Business Webcasts Downloads Powered by Bitpipe.com

Product Demos

Try out software demos Powered by 2020Software.com


Resource Centers

Red Hat Enterprise Virtualization Webinar Series View All Resource Centers Blogs
Blogs

Enterprise Linux Log I.T. Security and Linux Administration Powered by ITKnowledgeExchange.com Search this site SEARCH
Search

Home Topics Linux administration issues Introduction to Linux system administration Ten command line time-savers for Linux administrators

Ten command line time-savers for Linux administrators


Jason Gilmore, Contributor E-mail Print A AA AAA LinkedIn Facebook Twitter Share This RSS Reprints 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 an experienced system administrator. Although most of the following 10 tips focus on the Bash shell, all of these tips will be easily applicable to other modern shells. 1. Create and enter a directory using one command Creating 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 its 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 directory When you need to move from a deeply embedded directory and want to return to the original directory you could pass the previous path into 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 bookmarks Continuing along with the theme of directory interaction, there are some directories that you will inevitably return to time and again. It's possible 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 the following command:
$ cd books

4. Deftly edit the command line How many times have you tediously edited and executed a series of slightly dissimilar commands? Such as when building the PDF version 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 administration Get help from the community Powered by ITKnowledgeExchange.com up to retrieve the previously executed (above) command from history, and then arrowing left until replacing both instances of chapter06.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 found in the previously executed command with 04:
$ pandoc -o html/chapter06.html chapters/chapter06.md $ !!:gs/06/04 pandoc -o html/chapter04.html chapters/chapter04.md --template=templates/html.template --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 already binds the Alt key to toolbar commands. Alternatively you can use Shift + Alt as the meta key, but this is a bit awkward. Instead, if you don't require the toolbar command shortcuts, disable them by navigating to Edit -> Keyboard Shortcuts... and disable the Enable menu access keys option. 5. Saving a long command for later use When working through a sequence of system administration operations, it is possible to type a particularly long command and then realize before executing it a step in the sequence has been left out. Rather than deleting the command, you can save it to the history without executing 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 aliases The ls command's long listing format (ls -l) can be frequently used, but the hyphen makes it a bit unwieldy when typing furiously. You can create command aliases of for longer commands using the alias command within .bashrc. In this example, the command alias dir is substituted for ls -l:
alias dir='ls -l'

7. Saving more typing by ignoring typos You'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 and correct 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 background When cruising around the command line, you may need to do another task such as respond to an email. Of course, it's possible to open GUI 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 a particular 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 any image 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 forward slash (/) to search the file. The problem is that once you've found the desired string it's not possible to navigate up and inspect the contents that appeared prior to this string. The less command doesn't suffer from this disadvantage, allowing you to scroll both up and down within a text file. The less command is invoked in the same manner as more:
$ less sometextfile.txt

10. Clean up your command line history The history command is easily one of the most powerful tools at your disposal. But there is one timesaver in particular that deserves mention: the $HISTIGNORE shell variable. Over time your history list will become incredibly long. Take advantage of the $HISTIGNORE ;variable to mute the recording of any commands 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 you would 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 the author of several popular books, including Easy PHP Websites with the Zend Framework, Easy PayPal with PHP, and Beginning PHP 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 tips Enterprise Linux learning guide library Five Linux performance commands every admin should know Guide to the Linux security toolbox The top 10 Linux tips of 2010

Related tags admin linux

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) copyleft LiveDistro Yellowdog Updater, Modified (YUM) BSD (Berkeley Software Distribution) shell Free Software Foundation (FSF) Tcl/Tk (Tool Command Language) Show me more 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 other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the 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 2010 Enterprise 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 cloud freebie; openness of Android examined: news in brief Microsoft supports Red Hat Linux in Hyper-V IBM adapts mainframe for Linux, Red Hat

bolsters Express: News in brief View All News Enterprise Linux Topics
Topics
Ente rprise Linux applications and database s

Open source databases, Open source Web and application servers, Enterprise applications for Linux
Linux administration issue s

Linux administration tools, Linux management and configuration, Linux interoperability, Linux licensing and support, Linux monitoring and troubleshooting, Introduction to Linux system administration
Linux e nte rprise de sktops

Linux enterprise desktop distributions, Linux enterprise desktop applications


Linux in the data ce nte r

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 se curity

Linux security risks and threats, Linux system security best practices, Linux security tools
Linux se rve r 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 Linux Linux administration tools Linux virtualization Tutorials
Advice & Tutorials

A guide to becoming a Puppet master 77 useful Linux commands and utilities Open source virtualization digest A collection of the top Linux command tips Red Hat gives Windows the boot with RHEV 3.0

Technology Dictionary

Find definitions and links to technical resources Powered by WhatIs.com Expert Advice
Tips

Process monitoring and management on Red Hat using graphical tools Ten command line time-savers for Linux administrators How to install an OpenStack Nova compute cloud with Puppet View All Tips
Answers

Migrating infrastructure from Unix to Linux Installing Nagios on Linux and unravelling software code names Systems monitoring and tuning tools for RHEL 5 View All Answers
Ask a Question

Get help from our technical community Powered by ITKnowledgeExchange.com White Papers
Research Library

White Papers Business Webcasts Downloads Powered by Bitpipe.com


Product Demos

Try out software demos Powered by 2020Software.com


Resource Centers

Red Hat Enterprise Virtualization Webinar Series View All Resource Centers Blogs
Blogs

Enterprise Linux Log I.T. Security and Linux Administration Powered by

ITKnowledgeExchange.com Search this site SEARCH


More from Related TechTarget Sites Search

Data Center Server Virtualization Cloud computing Enterprise Desktop Data Center
Se tting up Linux HA in the data ce nte r

Learning to set up a basic Linux HA cluster using Corosync and Pacemaker can help protect vital services in the event of a hardware failure.

Evaluating mainframe syste m monitoring tools

There are many system monitoring tools available for mainframes. This tip can help administrators analyze and choose the tool that best fits their needs.

Surprise ! Data ce nte rs use d le ss e ne rgy than e xpe cte d

Data centers used less energy in the last five years than previously thought; and more data center facilities news in brief.

Server Virtualization
Shionogi bre ach spotlights virtualiz ation se curity

A disgruntled ex-employee admitted to deleting VMs at the pharmaceutical company, highlighting the need for proper enforcement of access-control policies in virtual environments.
Se rve r consolidation proje ct planning: Thre e ste ps to succe ss

As the Boy Scouts always say: Be prepared. With a server consolidation project, you can prepare for consolidation in three distinct phases.
Virtualiz ation storage pe rformance monitoring: Me trics and tools

Storage performance monitoring ensures that youre warned of low storage capacity and that youre up to date on virtualization storage usage trends. Cloud computing
Amaz on cloud me asure s up to e nte rprise at last

Is AWS ready to take on the enterprise? According to the cloud computing Magic 8 Ball, "Signs point to yes."
Amaz on GovCloud lurche s 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 can any enterprise buy one?
Eve n 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 advisors to assist them in figuring out how to best use the cloud. Enterprise Desktop
The limitations of re storing file s in Windows using Pre vious Ve rsions

Microsoft's Previous Versions function can retrieve files, but only copies made during a system checkpoint or snapshot. Our expert found a third-party backup tool to span the gap.
Microsoft to roll out 'critical' patche s 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 Kine ct could re volutioniz e IT administration

Microsoft Kinect has obvious implications for gaming, but a rumored integration with Windows 8 could mean big things for the future of IT. All Rights Reserved, Copyright 2003 - 2011, TechTarget About us Contact us Site index Privacy policy Advertisers Business partners Events Media kit TechTarget corporate site Reprints Site map

Você também pode gostar