Show Menu
Cheatography

Linux File Management Cheat Sheet (DRAFT) by

Commands used for file management in Linux

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Basic File Management

cp file name [-r creates destin­­ation]
mv Linux Command Cheatsheet to Linux
| is also for renaming
add -i, -n or -v
| ask first, no overwrite, show result
cat filename
| opens the file to read
less
| breaks results down into pages
mkdir\rm directory
rm
cd
touch
| creates a new file

Listing Files

-h
| human readable
-d
| lists the details
-R
| recursive [all sub-di­rec­tories]
-s
| sorts by name
-t
| sorts by time

Working with File Permis­­sions

chmod 777 [name of file]
| assign read, write & execute to all users
chmod 755 [name of file]
| read, write & execute for owner - read & execute for all other users
chmod 766 [name of file]
| full permission to owner - read and write to others
 
chown
| change ownership
 
[OPTIONS] [OWNER] FILE

File Compre­ssion

gzip
| common compre­ssion tool
gunzip

File Archiving

tar –cvf myback­ups­/ud­ev.tar /etc/udev
-c option tells the tar command to create a tar file.
-v option stands for "­ver­bos­e", which instructs the tar command to demons­trate what it is doing.
-f option is used to specify the name of the tar file.

Review Archive Contents

tar –tvf myback­ups­/ud­ev.tar

Create a Compressed Archive

tar –zcvf myback­ups­/ud­ev.t­ar.gz /etc/udev
| create an archive
tar –xvf udev.t­ar.gz
| extract an archive
tar -rvf udev.tar /etc/hosts
| add a file to existing archive
 

File type descri­ptors

Symbol
File Type
Descri­ption
d
| directory
| A file used to store other files.
-
| regular file
| Includes readable files, images files, binary files, and compressed files.
l
| symbolic link
| Points to another file.
s
| socket
| Allows for commun­ication between processes.
p
| pipe
| Allows for commun­ication between processes.
b
| block file
| Used to commun­icate with hardware.
c
| character file
| Used to commun­icate with hardware.

File Type

- rw-r--r-- 1 root root 15322 Dec 10 21:33 altern­ati­ves.log
d rwxr-xr-x 1 root root 4096 Jul 19 06:52 apt

Permis­sions

d rwxr-xr-x 2 root root 4096 Jul 19 06:51 journal

Hard Link Count

-rw-r----- 1 syslog adm 371 Dec 15 16:38 auth.log
drwxr-xr-x 2 root root 4096 Jul 19 06:51 journal

User Owner

-rw-r----- 1 syslog adm 197 Dec 15 16:38 cron.log

Group Owner

-rw-rw-r-- 1 root utmp 292584 Dec 15 16:38 lastlog

Timestamp

-rw-rw---- 1 root utmp 0 May 26 2018 btmp

File Size

-rw-r----- 1 syslog adm 14185 Dec 15 16:38 syslog
Displays the size of the file in bytes.

File Name

-rw-r--r-- 1 root root 35330 May 26 2018 bootst­rap.log
In the case of symbolic links, the link name is displayed along with an arrow and the pathname of the original file.

lrwxrw­xrwx. 1 root root 22 Nov 6 2018 /etc/g­rub.conf -> ../boo­t/g­rub­/gr­ub.conf