7. mv (move)
mv is used to move files. To move a file, type mv followed by the file you want to move and its destination as shown in the figure below.
mv options:
mv -f
Paksa pemindahan tanpa konfirmasi
example: mv -f source.txt destination.txt
mv -i
Meminta konfirmasi sebelum mengganti file
example: mv -i source.txt destination.txt
mv -u
Pindahkan hanya jika sumber lebih baru
example: mv -u source.txt destination.txt
mv -v
Menampilkan proses pemindahan secara rinci
example: mv -v source.txt destination.txt
mv -n
Tidak mengganti file yang sudah ada
example: mv -n source.txt destination.txt
8. cp (copy)
cp
command in Linux to copy files and directories from one location to another. It stands for “copy” and is a fundamental command-line utility for file management.
cp options:
cp -r
Recursive copy
example: cp -r /source /destination
cp -i
Interactive (prompt before overwrite)
example: cp -i file.txt /destination
cp -u
Update (copy if newer or missing)
example: cp -u file.txt /destination
cp -v
Verbose (detailed output)
example: cp -v file.txt /destination
cp -a
Archive (preserve attributes)
example: cp -a /source /destination
cp -f
Force (remove destination if needed)
example: cp -f file.txt /destination
cp – -backup
Create a backup of the destination
example: cp –backup file.txt /destination
cp -n
No clobber (do not overwrite)
example: cp -n file.txt /destination
9. ln (link)
a standard Unix command utility used to create a hard link or a symbolic link (symlink) to an existing file or directory
ls -s
Create a symbolic link
example: ln -s original.txt link.txt
ls -f
Force creation of the link, removing existing link
example: ln -f original.txt link.txt
is -i
Prompt before overwriting an existing link
example: ln -i original.txt link.txt
is -n
Treat the destination as a normal file
example: ln -n original.txt link.txt
is -v
Verbose output (show what is being done)
example: ln -v original.txt link.txt
command examples:
ln original.txt link.txt
Creates a hard link to ‘original.txt
‘
ln -s original.txt symlink.txt
Creates a symbolic link to ‘original.txt
‘
ln -f original.txt link.txt
Forces creation, overwriting ‘link.txt
‘
ln -i original.txt link.txt
Prompts before overwriting ‘link.txt
‘
ln -v original.txt link.txt
Verbose output during link creation
10. rmdir (remove directory)
mdir command to remove the directory, specified by the Directory parameter, from the system. The directory must be empty (it can contain only . and ..) before you can remove it, and you must have write permission in its parent directory.
rmdir <directory>
Remove an empty directory
example: rmdir /path/to/directory
rmdir -p <directory>
Remove a directory and its parent if empty
example: rmdir -p /path/to/directory
rmdir –ignore-fail-on-non-empty <directory>
Ignore errors if the directory is not empty
example: rmdir –ignore-fail-on-non-empty dir
some code that you can use:
rmdir -p /home/user/parent_dir/child_dir
Remove a Directory and Its Parent if Empty
rmdir /home/user/empty_dir
Remove an Empty Directory
rmdir –ignore-fail-on-non-empty /home/user/non_empty_dir
Ignore Errors for Non-Empty Directory
11. find
The ‘find’ command is your go-to tool for locating files and directories in a Linux system. It’s versatile, allowing you to search based on name, size, type, and other criteria.
find <path>
Search for files and directories in the specified path
example: find /home/user
find <path> -name <pattern>
Find files by name pattern
example: find /home/user -iname "*.jpg"
find /home/user -name “*.txt”
Find by type (e.g., f for files, d for directories)
example: find /home/user -type f
find <path> -size <size>
Find files by size
example:
find /home/user -size +1M
B
find <path> -exec <command> {} \;
Execute a command on found items
example: find /home/user -type f -exec rm {} \;
find <path> -mtime <n>
Find files modified in the last n days
example: find /home/user -mtime -7
find <path> -user <username>
Find files owned by a specific user
example:find /home/user -user alice
find <path> -iname <pattern>
Case-insensitive name search
example: find /home/user -iname “*.jpg”
12. du (Estimate File Space Usage)
du
command measures the file space usage for a given directory. When used without options, it displays disk usage for the current working directory.
du -h
Menampilkan Ukuran Direktori Saat Ini
example: du -h /path/to/directory/* | sort -h
Menampilkan Ukuran dengan Detail Lebih Dalam
du -s
Check Total Size of a Directory
example: du -s /path/to/directory
Check Total Size of a Directory
du -a
Show individual file sizes in addition to totals. Helps identify large files.
example: du -a /path/to/directory
Check Size of All Files and Directories