Ads by TechWords

See your link here
Receive the latest technology news and information.
Linux
Computerworld Daily News (First Look and Wrap-Up)
Computerworld Blogs Newsletter
The Weekly Top 10
Cloud Computing
View all newsletters




Privacy Policy
 

Linux Command-Line Cheat Sheet

August 14, 2007 12:00 PM ET

This article is reprinted from The Official Ubuntu Book, 2nd Edition, by Benjamin Mako Hill and Jono Bacon, with permission of publisher Prentice Hall Professional, copyright 2007, all rights reserved. While instructions are specific for Ubuntu Linux, most commands will work with other Linux distributions.

Moving Around the Filesystem

Commands for moving around the filesystem include the following.

  • pwd: The pwd command allows you to know the directory in which you're located (pwd stands for "print working directory"). For example, pwd in the desktop directory will show ~/Desktop. Note that the GNOME terminal also displays this information in the title bar of its window.

  • cd: The cd command allows you to change directories. When you open a terminal, you will be in your home directory. To move around the filesystem, use cd.
      •  To navigate to your desktop directory, use cd ~/Desktop
      •  To navigate into the root directory, use cd /
      •  To navigate to your home directory, use cd
      •  To navigate up one directory level, use cd ..
      •  To navigate to the previous directory (or back), use cd -
      •  To navigate through multiple levels of directories at once, use cd /var/www, for example, which will take you directly to the /www subdirectory of /var.



The Linux Command Line



Manipulating Files and Folders

You can manipulate files and folders by using the following commands.

  • cp: The cp command makes a copy of a file for you. For example, cp file foo makes an exact copy of the file whose name you entered and names the copy foo, but the first file will still exist with its original name. After you use mv, the original file no longer exists, but after you use cp, that file stays and a new copy is made.

  • mv: The mv command moves a file to a different location or renames a file. Examples are as follows: mv file foo renames the original file to foo. mv foo ~/Desktop moves the file foo to your desktop directory but does not rename it. You must specify a new filename to rename a file.

  • To save on typing, you can substitute ~ in place of the home directory.
    Note: If you are using mv with sudo, you will not be able to use the ~ shortcut. Instead, you will have to use the full pathnames to your files.

  • rm: Use this command to remove or delete a file in your directory. It does not work on directories that contain files.

  • ls: The ls command shows you the files in your current directory. Used with certain options, it lets you see file sizes, when files where created, and file permissions. For example, ls ~ shows you the files that are in your home directory.

  • mkdir: The mkdir command allows you to create directories. For example, mkdir music creates a music directory.

  • chmod: The chmod command changes the permissions on the files listed.
    Permissions are based on a fairly simple model. You can set permissions for user, group, and world, and you can set whether each can read, write, and/or execute the file. For example, if a file had permission to allow everybody to read but only the user could write, the permissions would read rwxr--r--. To add or remove a permission, you append a + or a - in front of the specific permission. For example, to add the capability for the group to edit in the previous example, you could type chmod g+x file.

  • chown: The chown command allows the user to change the user and group ownerships of a file. For example, chown jim file changes the ownership of the file to Jim.
Jump to comments

Linux

Additional Resources

EFD vs. HDD - What You Need to Know
WHITE PAPER
Enterprise flash drives provide a new Tier 0 storage layer capable of delivering high I/O performance at a very low latency. Proper use of EFDs in an Oracle environment can deliver increased performance compared to fibre channel drives. Read the recommendations for identification of the best DB components for EFDs.
Gartner Research Report: Magic Quadrant for Application Delivery Controllers, 2009
WHITE PAPER
The market for products to improve the delivery of application software over networks remains dynamic and innovative. Vendors focused on solving enterprises' most-pressing application problems have become the top players.
Eight Criteria for Server Load Balancing
WHITE PAPER
Server load balancers are a simple yet highly effective means to scale an application environment while ensuring its availability. Today's solutions should also address application performance and security. Read about the top eight criteria you should consider when choosing a server load balancer and how Citrix NetScaler meets those requirements.

What People Are Saying

White Papers & Webcasts

IDC Webcast: Linux Adoption in a Global Recession
Access this webcast, compliments of Novell and HP, for a limited time only!

The Workday User Experience Video
Watch Workday's Creative Director, Scott Lietzke, discuss the business-centered design philosophy at Workday.

Business Process Framework Demo
Learn about Configurable Business Processes and Calculated Fields. Watch Now!


IT Jobs