kentoh - Fotolia
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.
Dig Deeper on Data center server infrastructure and OSes
Related Q&A from Sander van Vugt
Linux has a security framework with multiple layers, which makes it hard to maintain permissions and privileges. User-based profiles and whitelisting... Continue Reading
Implementing RHEL in the cloud isn't exactly the same as using cloud technology in the data center, especially when addressing swap and support ... Continue Reading
Linux administrators should use syslog and systemd-journald together for smart log analysis. But there are also open source log management tools to ... Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.