Please enable JavaScript.
Coggle requires JavaScript to display documents.
Managing files - Coggle Diagram
Managing files
4.1. Using file management commands
Naming and listing files: ls -lh
Creating and naming files: touch
Determining a file's type: file
Wildcard examples
ls c*.txt
ls b?t
ls b[eio]t
ls b[a-z]t
ls b[^eio]t
Creating directories: mkdir
Listing directories with a / indicator: ls -F
Creating a directory and a subdirectory: mkdir -p DIRECTORY/SUBDIRECTORY/
Copying files: cp ORIGIN_FILENAME DESTINATION_FILENAME
Recursive copying: cp -R
Moving/ Renaming files: mv ORIGINAL_FILENAME RENAMED_FILENAME
Moving/ Renaming directories: mv -i
Deleting files interactively: rm -i
Deleting directories: rm -ir
Deleting directories recursively: rm -Ir
Compressing file commands
gzip
bzip2
xz
zip
Archiving file commands
dd
Syntax: dd if=INPUT_DEVICE of=OUTPUT_DEVICE [OPERANDS]
Copying an entire disk: dd if:/dev/sdb of=/dev/sdc status=progress
Zero an entire disk: dd if=/dev/zero of=/dev/sdc status=progress
tar
Creating an archive: tar -cvf PROJECTS.tar PROJECT?.txt
Creating a tarball: tar -zcvf PROJECTS.tar.gz PROJECT?.txt
Creating full backup: tar -g FULLBACKUP.snar -Jcvf PROJECTS.txz PROJECT?.txt
Creating incremental backup: tar -g FULL_ARCHIVE.snar -Jcvf PROJECTS_INC.txz
Listing a tarball's contents: tar -tf PROJECTS.tar.gz
Verifying backed-up files: tar -Wcvf PROJECTS.tar PROJECT?.txt
Extracting files from a tarball: tar -zxvf PROJECTS.tar.gz
cpio
Example: ls PROJECT?.txt | cpio -ov > PROJECTS.cpio
Listing files: cpio -itvI PROJECTS.cpio
Restoring files: copio -iv -no-absolute-filenames -I PROJECTS.cpio
Managing links
Creating a soft link: ln -s ORIGINAL_FILENAME SOFT_LINK_FILENAME
Creating a hard link: ln ORIGINAL_FILENAME HARD_LINK_FILENAME
4.2. Managing file ownership
Changing file's owner and group: chown NEW_OWNER:NEW_GROUP FILENAMES
Changing a file's group: chgrp [OPTIONS] NEW_GROUP FILENAMES
Changing a file's owner: chown [OPTIONS] NEW_OWNER FILENAMES
Viewing file owner and grouping settings: ls -l
4.3. Controlling access to files
ls command output
File owner
File group
Hard link count
File size
Permission string (rw-rw-r--)
Permissions
Write (w)
Execute (x)
Read (r)
Order of permissions
Group
Others
Owner
Last modification date
File type code
Socket file (s)
Named pipe or regular pipe (p)
Block device, as a hard drive (b)
Soft link (l)
Character device (c)
Directory (d)
Binary file, readable file, image file or compressed file (-)
Filename
Changing a file's mode
Symbolic mode
Symbolic mode levels
Group (p)
Other (o)
Owner (u)
All (a)
Signs
Add the permission (+)
Remove the permission (-)
Set the permission as the only permission (=)
Examples
chmod g-w PROJECT.txt
chmod ug=rwx PROJECT.txt
Octal mode
Octal mode permissions
Write and execute (3)
Read only (4)
Write only (2)
Read and execute (5)
Execute only (1)
Read and write (6)
No permissions (0)
Read, write and execute (7)
You must specify the three octal values for owner, group and other
Example: chmod 664 PROJECT.txt
User mask defines the default permissions and represents the bits to be removed from the default octal value
Default values
666 for files
777 for directories
Changing a user mask: umask 027
Special access modes
Set Group ID (SGID) tells Linux to run the program with the permission of the group. It is represented by an s in place of the execute permission letter for the group
Sticky bit is used on directories to protect unauthorized deletion. It is represented by a t in the execute bit position for others
Set User ID (SUID) tells Linux to run the program with the permissions of the file owner. It is represented by an s in place of the execute permission letter for the file owner
4.4. Locating files
Knowing what kind of file it is: type
Locating files based on data: find [PATH] [OPTION] [EXPRESSION]
find . -name "*.txt"
find . -maxdepth 2 -name "*.txt"
find /usr/bin -perm /4000
Finding files: locate
Locating any command's program binaries and source code files: whereis
Full path name of a shell command: which