Vous êtes sur la page 1sur 4

12 useful Linux file manipulation

Version 1.0
commands you should know May 23, 2005

By Mellonfire

Takeaway
This download shortens the Linux learning curve by providing a ready reference to common file system tasks and
their respective Linux commands.

Linux commands
There are certain file manipulation tasks common to every operating system. These include tasks like copying
and moving files, creating directories, creating and formatting partitions, and listing file contents.
Graphical operating systems like MacOS X and Microsoft Windows make it easy to perform these tasks through a
point-and-click interface. Users familiar with these systems can thus be forgiven their trepidation about making the
transition to Linux, which more closely resembles the MS-DOS command line. Although graphical interfaces do
exist for Linux (KDE at http://www.kde.org/ is a good example), command-line usage tends to be faster and
more flexible.
This download shortens the Linux learning curve by providing a ready reference to common file system tasks and
their respective Linux commands. Each command is described in brief, with a sample command line and a list of
useful options. Try these commands out for yourself as you read along, and you'll soon be a pro at working with
files in Linux!

Page 1
Copyright ©2005 CNET Networks, Inc. All rights reserved.
For more downloads and a free TechRepublic membership, please visit http://techrepublic.com.com/2001-6240-0.html
12 useful Linux file manipulation commands you should know

You Want Command Description Sample Useful Options


To Usage
Obtain a ls dir The ls command ls /tmp ƒ ls -al: List all
directory listing produces a listing of all files (including
the files in a directory. hidden files), with
Detailed information on complete file
file attributes such as details.
ownership and size can ƒ ls --color:
also be obtained with this Colorize listings by
command. file type
Copy a file cp source The cp command creates cp *.txt /tmp ƒ cp -i: Prompt
destination a copy of a file or before overwriting
directory. pre-existing files
ƒ cp -R: Copy
directories
recursively
ƒ cp -u: Update
destination only if
source is newer
Move or mv source The mv command moves mv data.txt ƒ mv -b: Backup
rename a file or destination a file or directory from /tmp/data.asc destination before
directory one location to another. It moving
can also be used to ƒ mv -i: Prompt
rename a file or directory. before overwriting
pre-existing files
Create a mkdir dir The mkdir command mkdir mkdir -p: Create
directory creates an empty /tmp/users/st parent directories if
directory in a specified uff they don't already exist
location.
Delete a file or rm file The rm command deletes rm ƒ rm -rf:
directory a file from the file system. /tmp/data.asc Recursively delete
It can also be used to directories (even if
delete directories. they contain files)
without prompting
Note: This operation is ƒ rm -i: Prompt
irreversible. before deleting files
or directories
Check disk or du dir The du command du /tmp ƒ du -h: Print disk
directory usage produces statistics on the usage values in
disk space consumed by human-readable
a particular directory and format
its subdirectories. ƒ du -s: Print
summary totals
only
ƒ du -S: Exclude
subdirectories from
disk usage
calculation
Check the file fsck The fsck command fsck / ƒ fsck -A: Check
system for filesystem checks a Linux file all mounted file
errors system for errors. It can systems for errors
optionally repair any ƒ fsck -r:
errors found. Interactively repair
the filesystem

Page 2
Copyright ©2005 CNET Networks, Inc. All rights reserved.
For more downloads and a free TechRepublic membership, please visit http://techrepublic.com.com/2001-6240-0.html
12 useful Linux file manipulation commands you should know

You Want Command Description Sample Useful Options


To Usage
Format a disk mkfs The mkfs command mkfs -t msdos ƒ mkfs -t type:
partition partition formats partition to use a /dev/hda1 Format using file
specified file system. A system type
variety of different file ƒ mkfs -c: Check
systems are supported, for bad blocks
including ext2, ext3, during format
reiserfs, FAT and VFAT
Note: This command
erases all data on the
named partition in an
irreversible operation.
Check a file's file file The file command file
type detects the type of a file. ~/stuff.zip
This is a quick way to
identify an unknown file.

Alter a file's chown owner The chown command chown ƒ chown -R:
ownership and file alters the user/group joe.users Recursively alter
permissions ownership of a file, while data.txt ownerships
chmod perms the chmod command ƒ chown -c: Print a
file alters the corresponding chmod 744 status message
read/write/execute data.txt only if ownership is
permissions. These actually changed
commands are invaluable
to set up access
privileges between
different users of a Linux
system.
Find a file by find path The find command find /tmp - ƒ find -maxdepth
name test pattern retrieves a list of all files name *.txt n: Search to a
matching a particular maximum of n
pattern in a directory tree. levels deep in the
Support for sophisticated directory tree
patterns makes this an ƒ find -mount:
extremely powerful Limit search to
search tool, and one you current file system
will use often.
Create a link or ln source The ln command ln -s ƒ ln -s: Create a
shortcut to a file destination creates a link to a file. /usr/local/my symbolic link
Linux supports both "soft" sql-4.0 ƒ ln -f: Overwrite a
(symbolic) and "hard" /usr/mysql pre-existing link
(real) links; ln's default with the same
behavior is to create hard name
links.
Note: You can obtain detailed help on any command by typing man command-name followed by Enter at the
Linux shell prompt.

Page 3
Copyright ©2005 CNET Networks, Inc. All rights reserved.
For more downloads and a free TechRepublic membership, please visit http://techrepublic.com.com/2001-6240-0.html
12 useful Linux file manipulation commands you should know

Additional resources
• Sign up for our TechRepublic NetNote, delivered on Mondays, Wednesdays, and Thursdays.
• Check out all of TechRepublic's newsletter offerings.
• Explore the possibilities of Linux networking with this primer (Download)
• Book Excerpt: Linux Quick Fix Notebook (Download)
• Point & Click Linux!: Dipping a toe into the command-line waters (Download)

Version history
Version: 1.0
Published: May 23, 2005

Tell us what you think


TechRepublic downloads are designed to help you get your job done as painlessly and effectively as possible.
Because we're continually looking for ways to improve the usefulness of these tools, we need your feedback.
Please take a minute to drop us a line and tell us how well this download worked for you and offer your
suggestions for improvement.

Thanks!

—The TechRepublic Downloads Team

Page 4
Copyright ©2005 CNET Networks, Inc. All rights reserved.
For more downloads and a free TechRepublic membership, please visit http://techrepublic.com.com/2001-6240-0.html

Vous aimerez peut-être aussi