0% found this document useful (0 votes)
61 views11 pages

Chapter 5: File Manipulation Commands

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views11 pages

Chapter 5: File Manipulation Commands

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Chapter 5: File Manipulation

Commands

©Copyright Network Development Group 2013.


Essential File Management
Commands
• ls - list files in a directory
• cp – copy files and directories
• mv – move and/or rename files and
directories
• rm – remove files and directories
• mkdir – make new directories
• rmdir – remove empty directories

©Copyright Network Development Group 2013.


The ls Command
• Lists files in a directory
• Defaults to current directory
• Common options:
–-a shows all files, including hidden files
–-S sorts output by file size
–-t sorts by time stamp
–-r reverses the sort
–-R shows files recursively
–-d displays directories, not their contents

©Copyright Network Development Group 2013.


ls -l
• The -l (long) option displays a long, detailed
listing
• Output includes:
- File type and permissions
- Hard link count
- User owner
- Group owner
- File size
- Timestamp
- File name

©Copyright Network Development Group 2013.


The file Command
• Displays what type of data the file contains
• Important because:
- many Linux commands require data that is
text-based, not binary
- unknowingly opening or viewing a binary
file may cause a terminal or window to
“hang” forcing a reset

©Copyright Network Development Group 2013.


The touch Command
• The touch command performs one of two
actions:
1) Updates the timestamp of an existing file.
* Defaults to updating modification timestamp
* -a will update access timestamp
* -c will update attribute change timestamp
2) Creates a new file(s) if the file name
argument(s) doesn’t/don’t already exist
• Some applications require a file(s) to exist
before they can be written to
• Great to create files to experiment with
©Copyright Network Development Group 2013.
The stat Command
• The stat command will display information
about a file, including all three timestamps

$ stat test/alpha.txt
File: 'test/alpha.txt‘
Size: 390 Blocks: 8 IO Block: 4096 regular file
Device: 58h/88d Inode: 13987 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1001/sysadmin) Gid: ( 1001/sysadmin)
Access: 2014-09-23 13:52:03.070012387 +0000
Modify: 2014-09-18 22:25:18.000000000 +0000
Change: 2014-09-23 13:52:03.070012387 +0000 Birth: -

©Copyright Network Development Group 2013.


The cp Command
• The cp command will copy a file
$cp old_file new_file
• To copy multiple files:
$cp /data/* ~
• Use the -v option to verify files that are
copied
• To copy a directory, use the -r option

©Copyright Network Development Group 2013.


The mv Command
• The mv command will move a file
$mv old_file new_file
• To move multiple files:
$mv /data/* ~
• To move a directory requires no special
option

©Copyright Network Development Group 2013.


The rm Command
• The rm command will permanently delete a
file:
$rm my_file
• Use the -i (interactive) option with
wildcards to avoid accidentally removing
files:
$rm -i *.txt
• Use the -r (recursive) option to delete
directories
$rm -r my_dir
©Copyright Network Development Group 2013.
The mkdir and rmdir Commands
• The mkdir command will create a directory
$mkdir mydir
• Use the -p option to create entire path:
$mkdir mydir/data
• The rmdir command will delete an empty
directory
$rmdir mydir

©Copyright Network Development Group 2013.

You might also like