0% found this document useful (0 votes)
49 views

CLI Commands

The document provides information about common commands used in Windows Command Prompt and Linux terminals. It covers commands for listing, copying, moving, deleting files and directories as well as searching, piping and redirection.

Uploaded by

Rui Gomes
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

CLI Commands

The document provides information about common commands used in Windows Command Prompt and Linux terminals. It covers commands for listing, copying, moving, deleting files and directories as well as searching, piping and redirection.

Uploaded by

Rui Gomes
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Windows

Command Prompt cmd.exe


PowerShell

List files and directories:


‘ls’ c:\
Get-Help ls or …/full – summary
ls -Force c:/ (show hidden files)

pwd – print woring directory


cd – change directory
cd .. -> takes 1 level relative to where you are
cd ~ - path of home directory

mkdir – make directory (mkdir my_cool_folder)


dealing with spaces: mkdir “my cool folder” or mkdir my` cool` folder (backtick ` tells to take
the next character as it is – AKA escape character)

history: shows the list of commands used in the past

CTRL+R :
# - allows to search for previous commands as well

copy: cp file.txt c:/desktop


using wildcard: * -> cp *.jpeg c:\users\desktop
copy a directory: (use -Recurse to copy all files inside) (used -Verbose to list what happens)
cp ‘new folder’ ~\desktop -Recurse -Verbose

RENAMEFILES and MOVE FILES


Use the MOVE Command
mv .\blue_doc.txt yellow_doc.txt

REMOVE FILES
rm or Remove
rm ~\text1.txt
rm ~\text1.txt -Force (to force deletion)
rm ~\my_directory_folder -Recurse (delete all inside a directory)

cat to view files contents


cat .\import.txt
more .\important.txt (enter: 1line/ space:1page/ q: quit)
cat .\fruit.txt -Head 10 (1st 10 lines of a file)
cat .\fruit.txt -Tail 10 (show last 10 lines of a file)

Get-Alias ls
Search on windows via GUI
used Indexin from startup search bar and on Users, advanced option to show contents as
well.
CLI: Select-String cow text.txt or use wildcard: Select-String cow *.txt (Search in all .txt files
for that word).

Looking for something in a directory, like only .exe.


Use: ls [directory] -Recurse -Filtre *.exe

PIPELINE in Windows
echo woof > dog.txt (create or override the file)
echo woof >> dog.txt (simply add to the existing file but does not override it)

cat dog.txt | Select-String ola


cat dog.txt | Select-String ola > newfileOla.txt

redirection
1: Stdout = 1>
2; Stderr = 2>

rm systemfile.bat 2> errors.txt or $null (to not show error on screen)

Linux
(/ is the root directory in Linux)

ls /
man ls
ls -l (list)
ls -l-a or ls -la – show all files and hidden files as well

pwd – print working directory


cd – change directory
cd ..
cd ~
+tab completion

mkdir my_cool_folder
backslash (\) in Linux is the escape character, which tells the shell to take the next char as
true value. Another way to do it is: mkdir ‘my cool folder’

CTRL+R : allows to search for previous commands as well


UP and DOWN keys for previous commands in order

COPY COMMAND
cp -r ‘my folder space’ ~/Desktop – needs to use -r(recursive) flag to copy all the folder’s
contents

RENAMEFILES and MOVE FILES


Use the MOVE Command
mv .\blue_doc.txt yellow_doc.txt
same for directories and use wildcard to move several files

REMOVE COMMANDS

rm command
rm text1.txt

display files
cat
less (like more on windows) /search
head fruit.txt (10 first lines of a file)
tail fruit.txt (10 last lines of a file)

find in linux
use grep command

grep cow farm_list.txt

PIPELINE and Redirection in Linux


echo woof > dog.txt (create or override the file)
echo woof >> dog.txt (simply add to the existing file but does not override it)

cat dog.txt | grep ola


cat dog.txt | grep ola > newfileOla.txt

redirection
1: Stdout = 1>
2; Stderr = 2>

rm systemfile.bat 2> errors.txt or $null (to not show error on screen)

<
$ cat < file.txt // The redirector is used for stdin.
File Contents Displayed as Input.

Less /var/log/syslog 2> /dev/null (output filtres from error messages)

Pipe to search on more detail


ls -la /etc | grep Bluetooth

Regular Expressions super powerful to learn.

You might also like