1.16 Create, delete, copy, and move files and directories

Create
To create empty file just type:

# touch filename

To create directory type:

# mkdir dirname

Delete
To delete any file or group of files use command rm

# rm filename

If you dont whant recive any promts, ignore nonexistent files and arguments, use option -f (force).

Empty directory can be deleted by command

# rm -d dirname

By default, rm does not remove directories. Use the --recursive (-r or -R) option to remove each listed directory, too, along with all of its contents.

One of most used command:

# rm -rf dirname

To remove a file whose name starts with a -, for example -foo, use one of these commands:

# rm -- -foo
or
# rm ./-foo

You can delete groups of file by using simple masking, for example to delete all Jpeg image file in folder you can use command:

# rm -f dirname/*.jpg

To remove a complex mask, use stream redirection and utility grep, for example next command remove all image files starts with a

# find dirname -type f | grep -E '^dirname/a.*[.]jpg$' | xargs -i rm -f {}

Copy
To copy file use command:

# cp source destination

To copy directories recursively use option -r

# cp -r sdir ddir

Move
To simple move file use command:

# mv oldname newname

To simple move directory you dont need use any options

# mv olddir newdir

To move group of file use command:

# mv -t destdir soursedir/*.jpg

CentOS 7

No features.

openSUSE Leap 42.3

No features.

Ubuntu 17.04

No features.

Publication/Release Date: Jul 11, 2017

Advertisement