In Unix programming, file management is an essential aspect of working with the file system. Here are some commonly used file management commands in Unix:
- ls: List files and directories in the current directory.Example:
ls
ls -l # Long format, showing detailed information
ls -a # Show hidden files
ls -lh # Long format with human-readable file sizes
- cd: Change the current working directory.Example:
cd /path/to/directory
cd .. # Move to the parent directory
cd # Change to the user's home directory
- pwd: Print the current working directory.Example:
pwd
- mkdir: Create a new directory.Example:
mkdir new_directory
- rmdir: Remove an empty directory.Example:
rmdir empty_directory
- cp: Copy files or directories.Example:
cp file.txt /path/to/destination/
cp -r directory /path/to/destination/ # Recursively copy directories
- mv: Move or rename files or directories.Example:
mv file.txt new_file.txt
mv directory /path/to/destination/ # Move directory to another location
mv old_name new_name # Rename a file or directory
- rm: Remove files or directories.Example:
rm file.txt
rm -r directory # Recursively remove directories and their contents
- touch: Create an empty file or update the timestamp of an existing file.Example:
touch new_file.txt
- cat: Concatenate and display the contents of a file.Example:
cat file.txt
- more / less: Display the contents of a file one screen at a time.Example:
more file.txt
less file.txt
- head / tail: Display the first or last few lines of a file.Example:
head file.txt
tail -n 10 file.txt # Show the last 10 lines of the file
- chmod: Change file permissions.Example:
chmod +x script.sh # Add execute permission to a script
chmod 644 file.txt # Set specific permissions (rw-r--r--)
- chown: Change file ownership.Example:
chown user:group file.txt
WATCH VIDEO TUTORIAL