Terminal commands relared to files in the Ubuntu
🔍 Viewing and Navigating Files
| Command | Description |
|---|---|
ls | List files and directories in the current directory |
ls -l | Long listing (with permissions, size, date, etc.) |
ls -a | Show hidden files (those starting with .) |
cd [directory] | Change directory |
pwd | Print current working directory |
tree | View directory structure in tree form (may need sudo apt install tree) |
📁 Creating and Managing Files
| Command | Description |
|---|---|
touch filename | Create a new empty file |
nano filename | Edit a file using nano text editor |
cat filename | View file contents |
more filename / less filename | Scroll through file contents |
cp file1 file2 | Copy a file |
mv oldname newname | Rename or move a file |
rm filename | Delete a file |
rm -i filename | Delete with confirmation |
rm -f filename | Force delete without confirmation |
📂 Working with Directories
| Command | Description |
|---|---|
mkdir directory_name | Create a directory |
mkdir -p path/to/directory | Create nested directories |
rmdir directory_name | Remove empty directory |
rm -r directory_name | Remove directory and contents recursively |
cd .. | Go up one directory level |
🔒 Permissions and Ownership
| Command | Description |
|---|---|
chmod [permissions] filename | Change file permissions |
chmod +x filename | Make a script executable |
chown user:group filename | Change file owner and group |
📦 Searching and Finding Files
| Command | Description |
|---|---|
find . -name "filename" | Find a file by name in current dir recursively |
locate filename | Quickly find a file (needs mlocate database) |
grep "text" filename | Search for text in a file |
grep -r "text" directory/ | Search recursively for text in directory |
📄 File Compression and Archiving
| Command | Description |
|---|---|
tar -cvf archive.tar file1 file2 | Create a tar archive |
tar -xvf archive.tar | Extract a tar archive |
zip archive.zip file1 file2 | Create a zip file |
unzip archive.zip | Extract a zip file |
Comments
Post a Comment
What is your thought about this?