Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

2.2 Basic File Commands

Uploaded by

Chaos Victoria
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

2.2 Basic File Commands

Uploaded by

Chaos Victoria
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

BASIC FILE COMMANDS

LINUX FILE SYSTEM (INCLUDING UNIX)

 File system does not have a drive letter


 Everything is considered as a file including directories and folders
 Directories or folder are considered special files
 A directory is a ‘file’ that contains files and directories
 The topmost directory or main directory in the file hierarchy is called root
 Represented as ‘/’
 The symbol ‘/’ is also used as a separator for directories
 Linux has a standard file hierarchy but may differ from between Linux
distributions
LINUX DIRECTORY STRUCTURE

 Linux distributions commonly follow this hierarchy:

root /
etc home usr dev kernel
user1 lib  Note: Linux file and folder
names are case sensitive
user2 sbin
LINUX DIRECTORY STRUCTURE

 Home Directory
 Is the directory allocated to each user on the system normally placed under the ‘Home’
OS directory – e.g. /home/alice
 A user has full control over his/her own home directory
 OS defaults to the user home directory when logging in to the terminal or opening a
shell
 shortcut representation of home directory ‘ ~ ’
WORKING WITH DIRECTORIES AND FILES

pwd
 Prints the directory including the path that the user is currently working in

cd [path]
 Changes to a different directory specified in the path
 Path can be:
 Absolute – pathname starts from root directory
 Relative – pathname starts from current working directory
WORKING WITH DIRECTORIES AND FILES

ls
 Lists files and folders in a directory
Option What it does
-a Lists all contents including hidden files and folders
-l Includes file metadata
-h Human readable file size, normally used together with –l
-d List current directory, normally used with –l
-R Recursive listing
-S List sorted by size (largest first)
-t List sorted by modification timestamp (most recent first)
WORKING WITH DIRECTORIES AND FILES -

 Metacharacters
 Can be used to specify patterns to match filenames in a directory
 Also referred to as “wildcards”
 Are interpreted by the shells first before running a command
Character Use Example
* represents zero or more Match files that start with a ‘t’ - ls /etc/t*
of any character
? represents a single Match any 3-letter file that starts with a ‘t’ - ls /etc/t??
character
[] Represents range of Match files that start with either a ‘t’ or ‘y’ - ls /etc/[ty]*
characters Match files that start with any letter from ‘t’ to ‘y’ - ls /etc/[t-y]*
! Used with [ ] to negate a Match files that do NOT start with a ‘t’ or ‘y’ - ls /etc/[!ty]
range
WORKING WITH DIRECTORIES AND FILES

touch [filename]
 Creates an empty file with the given file name
 Note: Linux filenames are at most 255 characters in length
rm [filename]
 Deletes a file or directory
Option What it does
-i Interactive mode (ask before delete)
-r Deletes a directory including contents
WORKING WITH DIRECTORIES AND FILES

mkdir [directory]
 Creates an empty directory with the given name
rmdir [directory]
 Deletes a directory if empty
Option What it does
-i Interactive mode (ask before delete)
WORKING WITH DIRECTORIES AND FILES

cp [source] [destination]
 Copy file specified by source to destination
Option What it does
-i Interactive mode (ask to overwrite if existing)
-n Do not overwrite
-r Copy including folders

mv [source] [destination]
 Move file specified by source to destination
 File retains name if destination filename is not specified
 Also has the –i and -n options
BASIC FILE COMMANDS

You might also like