Creating and Removing
-
touch: Create an empty file.
$ touch newfile.txt
-
mkdir: Create a new directory.
$ mkdir new_directory
$ rmdir empty_directory
Copying, Moving, and Renaming
-
cp: Copy files or directories.
-
-r: Recursively copy directories.
-
-i: Prompt before overwriting files.
$ cp source.txt destination.txt
$ cp -ri source_directory/ destination_directory/
-
mv: Move or rename files or directories.
-
-i: Prompt before overwriting files.
$ mv -i oldname.txt newname.txt
Listing and Navigating
$ pwd
-
cd: Change the current directory.
$ cd /path/to/directory/
File Content Viewing
-
cat: Display the entire content of a file.
$ cat file.txt
This is the content of file.txt.
-
less: View file content with pagination. No direct output, but provides an interactive view.
$ less file.txt
-
head: Display the beginning of a file.
$ head file.txt
First line of the file.
File and Directory Information
-
stat: Display detailed information about a file or directory.
$ stat file.txt
File: file.txt
Size: 1234 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 123456 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ user) Gid: ( 1000/ user)
-
file: Determine the type of a file.
$ file image.jpg
image.jpg: JPEG image data, JFIF standard 1.01
Searching for Files
-
find: Search for files in a directory hierarchy.
$ find /path/to/search/ -name "pattern*"
/path/to/search/pattern1.txt
/path/to/search/subdir/pattern2.txt
Top comments (0)