File Related Commands in Linux - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

File Related Commands in Linux

Share This

In this tutorial, we will discuss a few file-related commands which are frequently used.

file command

This command is used to determine the type of files. You can use the following options according to your requirement.

The command file * is used to list the types of all the files.

If the name of a directory is mentioned as file /directoryname/*, the list of all the file types from the mentioned directory is shown.

The command file [range]* will list out all the files starting from the alphabet present within the given range.

touch

This command is used to create a file. Different options can be used with touch command according to your requirements. To know more about this command you can visit the man page or you can use touch --help command to get details.

rm command

This command is used to remove a file from the file system.

The following options can be used at the time of using this command according to your requirement.

Instead of exact matching, if you mention part of the file/directory name, then all the files and directories with that matching will be deleted.

To delete a directory containing files and directories, you can use rm -r or R command as shown below.

The command rm -i is used to delete files interactively.

The rm -rf is used to remove a directory forcefully.

cp command

This command is used to copy a file. An example is shown below.

cp -r is used to copy a directory along with its sub directories.

cp file1.txt file2.txt directory_name is used to copy multiple files in a directory.

cp -backup is used to back up the existing file before overwriting it.

cp -i is used for confirmation before copying the file.

cp -l is used to create hard links to a file.

cp -u -v is used to make sure that source file is newer then destination file.

mv command

This command is used to rename or move a file.

You can also use the following options according to your requirements.

mv -i is used for taking permission to overwrite if a file exits with the same name.

mv * directoryname/ is used to move all the files from the present directory to a specific directory.

rm command

This command is used to remove a file.


Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.