kentoh - Fotolia

Q
Manage Learn to apply best practices and optimize your operations.

Which basic Linux file management commands should I know?

File management is an essential part of working within Linux. Knowing a few basic commands makes it easier to move content and avoid file misplacement.

Memorizing a few Linux file management commands will make your work as an IT administrator easier, and it can prevent file loss and disorganization.

Before you start any file management tasks, ensure that you're using the right permissions. Performing file management tasks as a non-root user has limitations; non-root users only have write permissions for the home and /tmp directories. The root user can create files anywhere within the operating system.

Another important requirement is knowing the file's location. The file system hierarchy standard is the organizational framework on Linux machines. This standard ensures that whatever distribution you use, you'll always find program files in /usr, log files in /var/log and temporary files in /tmp.

Basic Linux file management commands

The very first command you need to know is ls. This shows all the files in the currently selected directory. You can add -l to view additional file properties, such as the file owner and associated permissions. Running ls -a shows hidden files and ls -l shows the long output format so you can see all the file properties.

You'll also need Linux file management commands to copy and move files. Use the cp command to copy, and then use the mv command to move a file. For both commands, specify the name of the file as the first argument and the name of the destination directory as the second argument. For instance, cp /etc/hosts/tmp copies the /etc/hosts file to the /tmp directory.

Permissions also apply when copying or moving a file. Both commands require you to have read permissions for the original file and write permissions for the target directory. If you want to move a file, you'll need write permission for the original file directory. This is because moving a file takes it away from its original location, which makes it a directory operation.

The rm command allows you to remove a file; you simply type rm and the file name. For instance, rm /tmp/hosts will remove the file that you just copied to the /tmp directory. When removing files, you need write permissions on the directory that contains the file you want to remove.

Depending on which commands you use, the rm command removes individual files, as well as content directories. To do so, add the -r switch to the rm command. Implementing rm-r f /data will wipe the entire data directory, so be careful and confirm what data you're deleting. With Linux file management commands, once something is deleted, the backup tape is the only way to recover data.

This was last published in August 2018

Dig Deeper on Data center server infrastructure and OSes

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Join the conversation

1 comment

Send me notifications when other members comment.

Please create a username to comment.

What are your most commonly used Linux file management functions?
Cancel

-ADS BY GOOGLE

SearchWindowsServer

SearchServerVirtualization

SearchCloudComputing

Close