𝐌𝐚𝐧𝐢𝐩𝐮𝐥𝐚𝐭𝐢𝐧𝐠 𝐟𝐢𝐥𝐞𝐬 𝐚𝐧𝐝 𝐝𝐢𝐫𝐞𝐜𝐭𝐨𝐫𝐢𝐞𝐬

  • Wildcards:
Wildcards Meaning
* Matches any character
? Matches any single character
[characters] Matches any character that is a member of the set characters
[!characters] Matches any character that is not a member of the set characters
[:class:]] Matches any character that is member of the specified class
  • List of most commonly used character classes
Character class Meaning
[:alnum:] Matches any alphanumeric character
[:alpha:] Matches any alphabetic characters
[:digit:] Matches any numerical
[:lower:] Matches any lowercase letter
[:upper:] Matches any uppercase
  • Wildcard examples:
Pattern Matches
* All files
g* Any file beginning with g
b*.txt Any file beginning with b followed by any characters and ending with .txt
Data??? Any file beginning with Data followed by exactly three characters
[abc]* Any file beginning with either an a, a b, or a c
BACKUP.[0-9][0-9][0-9] Any file beginning with BACKUP. followed by exactly three numerals
[[:upper:]]* Any file beginning with an uppercase letter
[![:digit:]]* Any file not beginning with a numeral
*[[:lower:]123] Any file ending with a lowercase letter or the numerals 1, 2, or 3
  • Wildcards can be used with any command that accepts filenames as arguments

  • mkdir – make directory
    • mkdir dir – single directory
    • mkdir dir1 dir2 dir3 – multiple directories
┌──(darshan㉿kali)-[~/Desktop/practise]
└─$ mkdir commandline
                                                                                       
┌──(darshan㉿kali)-[~/Desktop/practise]
└─$ ls
commandline  TryHackMe


┌──(darshan㉿kali)-[~/Desktop/practise/commandline]
└─$ mkdir dir1 dir2 dir3
                                                                                       
┌──(darshan㉿kali)-[~/Desktop/practise/commandline]
└─$ ls
dir1  dir2  dir3


  • cp – copy files and directories
    • cp item1 item2 : copy single file item1 into item2
    • cp item... directory : copies multiple items (either files or directories) into a directory.
Option Meaning
-a,--archive Copy the files and directories and all of their attributes, including ownerships and permissions.
-i--interactive Before overwriting an existing file, prompt the user for confirmation.
-r--recursive Recursively copy directories and their contents. This option (or the -a option) is required when copying directories.
-u--update When copying files from one directory to another, only copy files that either don’t exist or are newer than the existing corresponding files in the destination directory. This is useful when copying large numbers of files as it skips files that don’t need to be copied
-v--verbose Display informative messages as the copy is performed.
  • mv is same as cp

  • rm file : remove files and directories
  • rm -rf file : remove entire directory in one command
Option Meaning
-i--interactive Before deleting an existing file, prompt the user for confirmation.
-r--recursive Recursively delete directories. This means that if a directory being deleted has subdirectories, delete them too. To delete a directory, this option must be specified.
-f--force Ignore nonexistent files and do not prompt. This overrides the –interactive option.
-v--verbose Display informative messages as the deletion is performed.

  • ln : create links
    • ln file link : create a hard link
    • ln -s item link : creates a symbolic link

Tags: mkdir, files, folders, bash, mv, rm, cp, cheatsheet, Linux Commands, Linux Command Line, cheat sheet, linux-commands, shell, SSH, bash

MIT license