The Art of File Handling on Linux
The Linux file system is a hierarchical structure that organizes and stores data on a computer. It follows a tree-like structure with a single root directory ("/") at the top, branching out into subdirectories and files. Linux uses various file systems such as ext4, XFS, Btrfs, and others to manage how data is stored and accessed. Files are treated as a series of bytes and are organized into blocks for efficient storage.?
???Dive Deeper:Check out this comprehensive guide on the Linux file system: https://chadura.com/blogs/the-art-of-file-handling-linux/
Linux supports several file types:
?
touch : Creates an empty file or updates the timestamp of an existing file.
touch newfile.txt
nano, vim, or gedit (graphical editor ) : Text editors used to create or edit files.
nano editor
nano filename.txt
? ? ? ? ? ? ? ? ? ?
vim editor
vim filename.txt
echo and print: Write text to a file.
Writes "Hello World" to file.txt.
echo "Hello World" > file.tx
printf "Hello World\n" > file.txt
?
cp: Copies files or directories.
cp source.txt destination.txt
cp -r : Copying files from Directories
cp -r sourcedir/ targetdir/?
mv : Moves or renames files and directories
mv file.txt newfile.txt
mv file.txt /path/to/destination/
rm : Deletes files.
rm filename.txt
rm -r directory/
rm -i filename.txt
File Permissions
Every file and directory in Linux has three permission levels: Owner, Group, and Others, each with three types of access:
Read (r) : View the contents of the file.
Write (w): Modify the file.
Execute (x): Run the file if it’s a script or program.
ls -l : Shows file permissions in the format drwxr-xr-x.?
Here:
chmod : Changes file permissions.
chmod 755 filename.txt
chmod u+x filename.sh
chown : Changes the ownership of a file or directory.
chown user group filename.txt
领英推荐
? ? ?File Compression and Archiving
tar : Archives multiple files into a single file.
tar -cvf archive.tar <input_directory>
tar -xvf archive.tar
gzip file.txt
gunzip file.txt.gz
zip archive.zip file1 file2
unzip archive.zip
Advanced File Handling Commands
find : Searches for files based on criteria (name, size, modification time, etc.).
find /path -name "*.txt"
find /path -type f -size +1M
locate:?Quickly finds files using a pre-built database.
locate filename
grep:?Searches for text patterns within files.
grep "pattern" filename.txt
grep -r "pattern" /path/
File Linking
ln :Creates hard or symbolic links.
Hard link:?Another name for a file, both references point to the same data on disk.
ln file1 file2
Symbolic link (symlink):?A shortcut or pointer to the original file.
ln -s file1 link_to_file
rsync:?Synchronizes files and directories between two locations. rsync is commonly used for backups or mirroring directories.
rsyncrsync -avz /source/ /destination/
du : Shows disk usage of files and directories.
du -sh directory/
du -h --max-depth=1 df
df -h:Displays disk space usage in human-readable format
pwd:?Prints the current working directory.
cd:?Changes the current directory.
cd /path/to/directory
cd.. : Moves to the specified directory.
cd ~ : Moves to the home directory.
#Linux #SysAdmin #Developers #TechTips #OpenSource