File - jasper-zanjani/dotfiles GitHub Wiki

exif

View image metadata. Unlike alternatives like file and ImageMagick's identify, exif produces columnar output [ref][31]

exif image.png 

fallocate

Create a file size of 1 gigabyte

fallocate -l 1G $FILENAME  # gibibyte
fallocate -l 1GB $FILENAME # gigabyte

file

View image metadata ostechnix.com

file image.png # => file type, dimensions, color depth

find

Search for files in a directory hierarchy Find all files in {$PATH} that are owned by {user}

find $PATH -user username

Find recently modified files/folders There are 3 timestamps associated with files in Linux 2daygeek.com

  • atime "access time": last time file was accessed by a command or application
  • mtime "modify time": last time file's contents were modified
  • ctime "change time": last time file's attribute was modified

Numerical arguments can be specified in 3 ways:

  • +n greater than {n} days ago
  • -n less than {n} days ago
  • n exactly {n} days ago
find $PATH -type f -mtime +120 -ls # Find only files that were modified more than 120 days ago
find $PATH -type f -mtime -15 -ls # Modified less than 15 days ago
find $PATH -type f -mtime 10 -ls # Modified exactly 10 days ago

# Find files modified over the past day
find $PATH -type f -newermt "1 day ago" -ls
find $PATH -type f -newermt "-24 hours" -ls
find $PATH -type f -newermt "yesterday" -ls

find $PATH -type f -ctime -1 -ls # Find files created today

install

Copy files while maintaining various metadata, including timestamp, owner, etc. [9]

Copy a file while preserving timestamp. The copy will have the install default of 755, but the original's mtime is maintained:

install --preserve-timestamp example/foo .

Copy a file, setting permissions, owner, and group

install --preserve-timestamp --owner=jdoe --group=sudoers --mode=753

ls

  a     d       h i     l           r   t            
            F                         S             Z

lsof

Display open files, open network ports, and network connections [23]

Option Effect
-i display network connections
-n prevent the conversion of IP addresses to hostnames
-P prevent the conversion of port numbers to port names

Show open network connections

sudo lsof -Pni

mkdir

Quickly create multiple directories using brace expansion

mkdir -p ~/my-app/{bin,lib,log}

Create new directory {dirname} along with all of the parents in its pathname, if they do not exist

mkdir -p dirname
mkdir --parents dirname

rename

rename uses regular expressions [Network World][https://www.networkworld.com/article/3433865/how-to-rename-a-group-of-files-on-linux.html#tk.rss_linux]

Option POSIX option Effect
-n --nono dry-run: describe the changes the command would make, without actually doing them

Rename multiple files

# Renaming file.old to file.new
rename 's/old/new/' this.old

# Use globbing to rename all matching files
rename 's/old/new/' *.old
rename 's/report/review/' *

# Change all uppercase letters to lowercase
rename 'y/A-Z/a-z/' *

rsync

  a b     e   g         l     o p   r   t   v       z

Copy $FILE locally 2daygeek.com

rsync -zvr $FILE $PATH

Copy $FILE to $PATH on remote $HOST

rsync $FILE $HOST:$PATH

Copy $FILE from $HOST to local $PATH

rsync $HOST:$FILE $PATH

Copy $DIR recursively 2daygeek.com

rsync -zvr $DIR $PATH
rsync -avz $DIR $PATH

Copy to remote systems over SSH 2daygeek.com

rsync -zvre ssh $DIR $HOST:$REMOTEPATH
rsync -avze ssh $DIR $HOST:$REMOTEPATH

Synchronize only specific file type 2daygeek.com

rsync -zvre ssh --include '*.php' --exclude '*' $PATH

setfacl

Set file access control list

Option POSIX option Description
-b --remove-all remove all extended ACL entries, retaining the base ACL entries of the owner, group, and others
-k --remove-default remove the Default ACL
-m --modify modify ACL of a directory
-M --modify-file modify ACL of a file
-s overwrite or set
-x --remove remove ACL entries from a directory
-X --remove-file remove ACL entries from a file

Grant user {lisa} right to read {file}

setfacl -m u:lisa:r file

Remove named group {staff} from {file}'s ACL

setfacl -x g:staff file

Modify file access control list for {file} to revoke write access from all groups and all named users

setfacl -m m::rx file

Grant read access to other users

setfacl -m o::rwx file4.txt

Add user {zach} to list of users of file4.txt

setfacl -m u:zach:rw file4.txt

shred

Write random data to an unmounted disk for {n} passes

shred --iterations=n

touch

Network World

tree

Display contents of directories in a tree-like format [tecmint.com](https://www.tecmint.com/linux-tree-command-examples/ "tecmint.com: "Linux tree command usage examples for beginners"")

Option Effect
-a all files
-d display directories only
-f display full path prefix for each file
-g display group name or GID for each file
-p display permissions, similar to ls -l
-u display username or UID
-L $N limit to $N maximum depth
-I $PATTERN suppress files matching $PATTERN
-P $PATTERN display only files matching $PATTERN
--prune suppress empty directories
⚠️ **GitHub.com Fallback** ⚠️