[go: up one dir, main page]

Open In App

File Management in Linux

Last Updated : 24 Feb, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In Linux, most of the operations are performed on files. And to handle these files Linux has directories also known as folders which are maintained in a tree-like structure. Though, these directories are also a type of file themselves. Linux has 3 types of files:

  1. Regular Files: It is the common file type in Linux. it includes files like – text files, images, binary files, etc. Such files can be created using the touch command. They consist of the majority of files in the Linux/UNIX system. The regular file contains ASCII or Human Readable text, executable program binaries, program data and much more.
  2. Directories: Windows call these directories as folders. These are the files that store the list of file names and the related information. The root directory(/) is the base of the system, /home/ is the default location for user’s home directories, /bin for Essential User Binaries, /boot – Static Boot Files, etc. We could create new directories with mkdir command.
  3. Special Files: Represents a real physical device such as a printer which is used for IO operations. Device or special files are used for device Input/Output(I/O) on UNIX and Linux systems. You can see them in a file system like an ordinary directory or file.

In Unix systems, there are two types of special files for each device, i.e. character special files and block special files. For more details, read the article Unix file system.

1. Files Listing

To perform Files listings or to list files and directories ls command is used

$ls

ls-command-1

All your files and directories in the current directory would be listed and each type of file would be displayed with a different color. Like in the output directories are displayed with dark blue color.

$ls -l

ls-command-2

It returns the detailed listing of the files and directories in the current directory. The command gives os the owner of the file and even which file could be managed by which user or group and which user/group has the right to access or execute which file.

2. Creating Files

touch command can be used to create a new file. It will create and open a new blank file if the file with a filename does not exist. And in case the file already exists then the file will not be affected.

$touch filename

touch-command

3. Displaying File Contents

cat command can be used to display the contents of a file. This command will display the contents of the ‘filename’ file. And if the output is very large then we could use more or less to fit the output on the terminal screen otherwise the content of the whole file is displayed at once.

$cat filename

cat-command

4. Copying a File

cp command could be used to create the copy of a file. It will create the new file in destination with the same name and content as that of the file ‘filename’.

$cp source/filename destination/

copying-a-file-in-linux

5. Moving a File

mv command could be used to move a file from source to destination. It will remove the file filename from the source folder and would be creating a file with the same name and content in the destination folder.

$mv source/filename destination/

moving-a-file-in-linux

6. Renaming a File

mv command could be used to rename a file. It will rename the filename to new_filename or in other words, it will remove the filename file and would be creating a new file with the new_filename with the same content and name as that of the filename file.

$mv filename new_filename

renaming-a-file-in-linux

7. Deleting a File

rm command could be used to delete a file. It will remove the filename file from the directory.

$rm filename

deleting-a-file-in-linux


Similar Reads

Kali Linux - File Management
In Kali Linux, most of the operations are performed on files. And to handle these files Kali Linux has directories also known as folders which are maintained in a tree-like structure. Though, these directories are also a type of file themselves. Kali Linux has 3 basic types of files: Regular Files: It is the common file type in Linux. it includes f
4 min read
How to Fix - Cp: Cannot Create Regular File 'File': File Exists
In Linux, while performing copying operations using the cp command, the error "Cp: Cannot Create Regular File 'File': File Exists" may occur when attempting to copy a file to a destination where a file with the same name already exists. This error is a safeguard to prevent accidental overwriting of files and potential data loss. To resolve this iss
3 min read
User Management in Linux
A user is an entity, in a Linux operating system, that can manipulate files and perform several other operations. Each user is assigned an ID that is unique for each user in the operating system. In this post, we will learn about users and commands which are used to get information about the users. After installation of the operating system, the ID
4 min read
What is init.d in Linux Service Management?
In Linux there are several services that can be started and stopped manually in the system, some of their services are ssh, HTTP, tor, apache, etc. To start and run these services we used to simply type service "service name" start/stop/status/restart Example: service ssh start And to check if this service is running we type the command service ssh
2 min read
Group Management in Linux
There are 2 categories of groups in the Linux operating system i.e. Primary and Secondary groups. The Primary Group is a group that is automatically generated while creating a user with a unique user ID simultaneously a group with an ID the same as the user ID is created and the user gets added to the group and becomes the first and only member of
4 min read
Process Management in Linux
A process means program in execution. It generally takes an input, processes it and gives us the appropriate output. Check Introduction to Process Management for more details about a process. There are basically 2 types of processes. Foreground processes: Such kind of processes are also known as interactive processes. These are the processes which
3 min read
Command-Line Tools and Utilities For Network Management in Linux
If you are thinking of becoming a system administrator, or you are already a system admin, then this article is for you. As a system admin, your daily routine will include configuring, maintaining, troubleshooting, monitoring, securing networks, and managing servers within data centers. Network configuration and troubleshooting are some important t
8 min read
YUM Commands for Linux Package Management
If you are a Linux user or system administrator, chances are you've come across YUM (Yellowdog Updater, Modified) at some point in your journey. YUM is a powerful package management tool that simplifies the process of installing, updating, and managing software on Red Hat-based Linux distributions like CentOS and Fedora. In this article, we will de
4 min read
Linux Process Management Command Cheat Sheet
On Linux computers there are special commands to control the programs that are running. These commands are called process management commands. With the help of process management commands you can look at the list of the programs that are currently running on your computer. You can also start new programs and run them and stop programs that are alre
6 min read
Debian Software Package Management(dpkg) in Linux
In Linux, there are a lot of different distributions and each of these distributions has a different package type.  For example .rpm or Red hat Package Manager is used as the package in the Linux distribution. A package is the compressed version of the software. In this article, we will go through the Debian package which is used by Ubuntu. D packa
4 min read