Sei sulla pagina 1di 4

Mkdir

OPTIONS: -m Set the access mode for the new directories. -p Create intervening parent
directories if they don't exist. -v Print help message for each directory created.

EXAMPLE:

1. Create directory:

mkdir test The above command is used to create the directory 'test'.

2. Create directory and set permissions:

mkdir -m 666 test The above command is used to create the directory 'test' and set the read and
write permission.

mkdir -m a=rwx mydir This next example would use the -m option to not only create the mydir
directory but also set the permissions to all users having read, write, and execute permissions.

rmdir COMMAND: rmdir command is used to delete/remove a directory and its subdirectories.

SYNTAX: The Syntax is rmdir [options..] Directory

OPTIONS:

-p Allow users to remove the directory dirname and its parent directories which become empty.

EXAMPLE:

1. To delete/remove a directory

rmdir tmp rmdir command will remove/delete the directory tmp if the directory is empty.

2. To delete a directory tree:

rm -ir tmp This command recursively removes the contents of all subdirectories of the tmp directory,
prompting you regarding the removal of each file, and then removes the tmp directory itself.

rm COMMAND: rm linux command is used to remove/delete the file from the directory.

SYNTAX: The Syntax is rm [options..] [file | directory]

OPTIONS: -f Remove all files in a directory without prompting the user. -i Interactive. With this
option, rm prompts for confirmation before removing any files.

-r (or) -R

Recursively remove directories and subdirectories in the argument list. The directory will be emptied
of files and removed. The user is normally prompted for removal of any write-protected files which
the directory contains.

EXAMPLE:
1. To Remove / Delete a file:

rm file1.txt Here rm command will remove/delete the file file1.txt.

2. To delete a directory tree:

rm -ir tmp This rm command recursively removes the contents of all subdirectories of the tmp
directory, prompting you regarding the removal of each file, and then removes the tmp directory
itself.

3. To remove more files at once

rm file1.txt file2.txt rm command removes file1.txt and file2.txt files at the same time.

chmod COMMAND: chmod command allows you to alter / Change access rights to files and
directories.

File Permission is given for users,group and others as,

Read Write Execute User Group Others

Permission Symbolic Mode

SYNTAX: The Syntax is chmod [options] [MODE] FileName

File Permission

# File Permission 0 none 1 execute only 2 write only 3 write and execute 4 read only 5 read and
execute 6 read and write 7 set all permissions

OPTIONS: -c Displays names of only those files whose permissions are being changed -f Suppress
most error messages -R Change files and directories recursively -v Output version information and
exit.

EXAMPLE:

1. To view your files with what permission they are:

ls -alt This command is used to view your files with what permission they are.

2. To make a file readable and writable by the group and others.

chmod 066 file1.txt 3. To allow everyone to read, write, and execute the file

chmod 777 file1.txt

Ls: ls COMMAND: ls command lists the files and directories under current working directory.

SYNTAX: The Syntax is ls [OPTIONS]... [FILE]

OPTIONS: -l Lists all the files, directories and their mode, Number of links, owner of the file, file
size, Modified date and time and filename. -t Lists in order of last modification time. -a Lists all
entries including hidden files. -d Lists directory files instead of contents. -p Puts slash at the end of
each directories. -u List in order of last access time. -i Display inode information. -ltr List files order
by date. -lSr List files order by file size.

EXAMPLE:

1. Display root directory contents:

ls / lists the contents of root directory.

2. Display hidden files and directories:

ls -a lists all entries including hidden files and directories.

3. Display inode information:

ls -i 7373073 book.gif 7373074 clock.gif 7373082 globe.gif 7373078 pencil.gif 7373080 child.gif
7373081 email.gif 7373076 indigo.gif The above command displays filename with inode value.

cat COMMAND: cat linux command concatenates files and print it on the standard output.

SYNTAX: The Syntax is cat [OPTIONS] [FILE]...

OPTIONS: -A Show all.

-b Omits line numbers for blank space in the output. -e A $ character will be printed at the end of
each line prior to a new line. -E Displays a $ (dollar sign) at the end of each line. -n Line numbers for
all the output lines. -s If the output has multiple empty lines it replaces it with one empty line. -T
Displays the tab characters in the output. -v Non-printing characters (with the exception of tabs,
new-lines and form-feeds) are printed visibly.

EXAMPLE:

1. To Create a new file:

cat > file1.txt This command creates a new file file1.txt. After typing into the file press control+d (^d)
simultaneously to end the file.

2. To Append data into the file:

cat >> file1.txt To append data into the same file use append operator >> to write into the file, else
the file will be overwritten (i.e., all of its contents will be erased).

3. To display a file:

cat file1.txt This command displays the data in the file.

4. To concatenate several files and display:

cat file1.txt file2.txt The above cat command will concatenate the two files (file1.txt and file2.txt)
and it will display the output in the screen. Some times the output may not fit the monitor screen. In
such situation you can print those files in a new file or display the file using less command.
cat file1.txt file2.txt | less

5. To concatenate several files and to transfer the output to another file.

cat file1.txt file2.txt > file3.txt In the above example the output is redirected to new file file3.txt. The
cat command will create new file file3.txt and store the concatenated output into file3.txt.

cp COMMAND: cp command copy files from one location to another. If the destination is an
existing file, then the file is overwritten; if the destination is an existing directory, the file is copied
into the directory (the directory is not overwritten).

SYNTAX: The Syntax is cp [OPTIONS]... SOURCE DEST cp [OPTIONS]... SOURCE... DIRECTORY


cp [OPTIONS]... --target-directory=DIRECTORY SOURCE...

OPTIONS: -a same as -dpR. --backup[=CONTROL] make a backup of each existing destination file -
b like --backup but does not accept an argument. -f if an existing destination file cannot be opened,
remove it and try again. -p same as --preserve=mode,ownership,timestamps. --preserve[=ATTR_LIS
T] preserve the specified attributes (default: mode,ownership,timestamps) and security contexts, if
possible additional attributes: links, all. --no-preserve=ATTR_L IST don't preserve the specified
attribute. --parents append source path to DIRECTORY.

EXAMPLE:

1. Copy two files:

cp file1 file2

The above cp command copies the content of file1.php to file2.php.

2. To backup the copied file:

cp -b file1.php file2.php Backup of file1.php will be created with '~' symbol as file2.php~.

3. Copy folder and subfolders:

cp -R scripts scripts1 The above cp command copy the folder and subfolders from scripts to scripts1

Potrebbero piacerti anche