While working with Linux computers, you spend a lot of time managing files, folders, and directories. In the Linux operating system, every single entity is referred to as a file. Most of the files are block files, and some include symbolic links.
The setup is a bit different from other operating systems, most notably MS Windows and macOS. Even file conversions can be complicated on these two, as indicated here, due to various limitations.
Working in Linux means dealing with a lot of terminal commands as they give you complete control over your system in comparison to the graphical elements.
The article explains some of the top Linux file management tips that allow you to keep everything organized on your computer.
Before you get started, launch the terminal by pressing Ctrl + Alt + T keys together.
The Print Working Directory (pwd) is a command that prints out the working directory in a hierarchy. It starts with the top-level root directory and flows downwards.
$ pwd: Type in $ pwd to analyze your current working directory in the Linux operating system.
The output will show you what directory you are in by displaying the full path on the screen. For example, if the output says /home, it Indicates you are in the home directory.
This is a dynamic command that can be used in different ways, such as renaming a file, changing the file extension, or relocating the file from one folder to another. The output is based on the way it is used.
$ mv filename1 filename2: Use this syntax to rename the file from the original name to the one specified in the command. For example, $ mv file1.txt file2.txt
$ mv filename.oldextension filename.newextension: It will change the file extension of the given file. The example given will change the php file to html format. To change index.php to index.html, you may type in $ mv file1.php file.html.
$ mv filename /path/to/destination: It will move the specified files from the given path to the mentioned destination. For example, $mv file1.txt Downloads/docs
This is something that most of us have used while learning computers in the school or tertiary levels. The mkdir commands build a new directory on your Linux computer. mkdir in Linux is the short form used for making a directory.
$ mkdir directory_name: Use this syntax to create a new directory where directory_name is the name of the directory that you want to build. For example, $ mkdir javaproject.
$ mkdir -p javaproject/linux/core: The -p flag allows you to create a new directory within the current directory. In this example, the system will create a directory named Core within the Linux directory within Javaproject, which is the parent directory.
Learning Linux commands is fun as you can use some of these Linux commands on macOS as well as Windows computers. Cd in Linux stands for Change Directory command. Use the cd command when you need to change or navigate the directories.
$ Cd..: Using the cd command, if you want to move upwards in the directory structure, type in $ cd..
$ Cd: Type in $ cd without any argument to go to the home directory.
$Cd Downloads: When you want to navigate to the Downloads directory, type in $ cd Downloads. Do not use the forward-slash ( / ) when you want to move to a directory or a subdirectory within the current directory.
When you want to list the files and folders in the directory, use the ls command. The command helps you to enlist all the contents stored within the home directory. The folders will be displayed by their respective names. The items that are displayed in .txt format are the files that you have stored in the selected directory.
$ Ls -Lh: If you wish to retrieve more information about the files and folders stored in the directory, append -lh with the ls command. The -l flag displays any additional information such as user, group, file permission, date of creation, file size, and so on. The -h flag displays the information in a format that is easily readable.
$ Ls -La: Using -a flag with the ls command will enlist the hidden items. The output will contain all the hidden files that start with a period (.) sign, for example, .ssh, .local, or .config.
This command can be used to create simple files on the Linux computer.
$ Touch Filename: The syntax allows you to create a file, where ‘filename’ is the name of the file, for example, $ touch file1.txt. Additionally, you can invoke the ls command to confirm the file creation on the system as it will list the files, and you would be able to check if the file is created successfully.
The rm command is used in Linux to delete a file, while you can use rmdir command to remove a directory.
$ Rm Filename: Using this command is simple as you need to provide the name of the file that you want to remove, for example, $ rm file1.txt.
$ Rmdir Filename: Use this command with the directory name to delete it from the computer.
After creating the file, use the cat command to view the contents stored within it. You must provide the filename with the command to instruct the system to display its contents, for example, $ cat file1.txt.