Ctrl+C
Ctrl+X
Ctrl+V
Win+Shift+S
Win+PrtScn
Fn+Win+Space
.Alt+Space
Win+Ctrl+T
Win+Shift+C
Win+Shift+T
Win+Shift+Q
F11
or Win+UpArrow
Win+Tab
Win+D
Alt+Tab
Win+X
Win+L
The window, which is usually called the command line or command-line interface, is a text-based application for viewing, handling, and manipulating files on your computer. It's much like Windows Explorer or Finder on the Mac, but without the graphical interface. Other names for the command line are:
cmd, CLI, prompt, console or terminal
While there are many commands you can use with CLI, they all fall into two categories:
The commands that handle the processes
The commands that handle the files
[reference](Introduction to command line · HonKit)
Go to the Start menu or screen, and enter Command Prompt
in the search field.
Go to Start menu → Windows System → Command Prompt
.
Go to Start Menu → All Programs → Accessories → Command Prompt
.
Go to the Start screen, hover your mouse in the lower-left corner of the screen, and click the down arrow that appears (on a touch screen, instead flick up from the bottom of the screen). The Apps page should open. Click on Command Prompt in the Windows System section.
Hold the special Windows key on your keyboard and press the "X" key. Choose "Command Prompt" from the pop-up menu.
Hold the Windows key and press the "R" key to get a "Run" window. Type "cmd" in the box, and click the OK key.
It's probably under
> whoami (hit enter)
> pwd
>cd
>man <command_name>
Sample
>man pwd
OS X and Linux have a man command,which gives you help on commands
Use the space
bar to move to the next page, and q
to quit looking at the help
/?
suffix to most commands will print the help page>cd /?
>ls
>ls -R
>ls -a
>ls -al
>dir
Result:
Volume in drive C is Windows
Volume Serial Number is 8C3C-8F8C
Directory of C:\Users\ugur.coruh
10/14/2020 09:57 AM <DIR> .
10/14/2020 09:57 AM <DIR> ..
08/15/2020 11:00 PM <DIR> .android
06/28/2020 03:02 AM <DIR> AndroidStudio4.0
brew install tree
> tree
Result:
C:\Users\ugur.coruh\Desktop\Samples>tree
Folder PATH listing for volume Windows
Volume serial number is 8C3C-8F8C
C:.
├───C
│ └───HelloWorld
│ └───.vscode
├───Cpp
├───Csharp
└───Java
>cd <path>
cd Desktop
tab
to complete or find> cd ..
cd ..\..\..
to go 3 level up.cd ..\..\target\child
cd C:\temp\build\target\child
>cd-
(with a hyphen) to move to your previous directory
> mkdir folder_name
mkdir Music/Newfile
use the p
(parents) option to create a directory in between two existing directories.
For example, mkdir -p Music/2020/Newfile
will
create the new “2020” file.
ls
dir
or tree
> dir
> cd folder_name
> rm –r folder_path
>rmdir
-r
is used for recursive deletion
of folders.
However, rmdir
only allows you to delete empty directories
> rmdir /S folder_path
folder_path, Are you sure
<Y/N>? Y
>DEL /F untitled.txt*
Use the cp
command to copy files from the current directory to a different directory.
For instance, the command cp scenery.jpg /home/username/Pictures
would create a copy of scenery.jpg
(from your current directory) into the Pictures
directory.
cd-
(with a hyphen) to move to your previous directoryCopy a file in the current folder>COPY source_file.doc newfile.doc
folder/directory:
>COPY "C:\my work\some file.doc" "D:\New docs\newfile.doc"
>COPY "C:\my work\*.doc"
>COPY "C:\my work\*.txt" "D:\New docs\combined.txt"
COPY source_file.doc newfile.doc >nul
Echo n|COPY /-y c:\demo\source_file.txt c:\dir\dest.txt
>REN d:untitled.txt untitled1.txt*
REN [drive:][path] [source] [target]
>REN d:untitled.txt ..\..\folder\untitled1.txt*
>REN d:untitled.txt C:\folder\untitled1.txt
>mv [OPTIONS] source destination*
>mv file1.txt file2.txt*
sudo apt install rename
>MOVE oldfile.wp newfile.doc
>MOVE g:\department\oldfile.wp "c:\Files to
Convert\newfile.doc"
>MOVE a:oldfile.wp c:newfile.doc
>MOVE g:\department\oldfile.wp
>MOVE oldfile.wp newfile.doc >nul
>Echo n|MOVE /-y c:\file1.txt c:\dir\file1.txt
Check mv
command
For example: mv file.txt /home/username/Documents
D:\ > LABEL d:MyData
> Measure-Command {echo hi}
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 0
Ticks : 1318
TotalDays : 1.52546296296296E-09
TotalHours : 3.66111111111111E-08
TotalMinutes : 2.19666666666667E-06
TotalSeconds : 0.0001318
TotalMilliseconds : 0.1318
> powershell -Command "Measure-Command {echo hi}"
timecmd.bat
@echo off
@setlocal
set start=%time%
:: Runs your command
cmd /c %*
set end=%time%
set options="tokens=1-4 delims=:.,"
for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100
set /a hours=%end_h%-%start_h%
set /a mins=%end_m%-%start_m%
set /a secs=%end_s%-%start_s%
set /a ms=%end_ms%-%start_ms%
if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
if %hours% lss 0 set /a hours = 24%hours%
if 1%ms% lss 100 set ms=0%ms%
:: Mission accomplished
set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
echo command took %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)
Usage
timecmd.bat
in a directory in your path, you can call it from anywhere like this:>timecmd [your command]
C:\>timecmd
pause
Press any key to continue .
. . command took 0:0:1.18
timecmd "dir c:\windows /s > nul"
cat
(short for concatenate) is one of the most frequently used commands in Linux. It is used
to list the contents of a file on the standard output (sdout). To run this command, type cat
followed by the file’s name and its extension. For instance: cat file.txt
.
Here are other ways to use the cat
command:
cat > filename
creates a new file
cat filename1 filename2>filename3
joins two files (1 and 2) and stores the output of them in a new file (3)
to convert a file to upper or lower case use, cat
filename | tr a-z A-Z >output.txt
touch
command allows you to create a blank new file through the Linux command line. As an example, enter touch /home/username Documents/Web.html
to create an HTML file entitled Web
under the Documents
directory.You can use this command to locate
a file, just like the search command in Windows. What’s more, using the -i
argument along with this command will make it case-insensitive, so you can search for a file even if you don’t remember its exact name.
To search for a file that contains two or more words, use an asterisk (*
). For example, locate -i school*note*
command will search for any file that contains the word “school
” and “note
”, whether it is uppercase or lowercase.
Similar to the locate
command, using find
also searches for files and directories. The difference is, you use the find
command to locate files within a given directory.
As an example, find /home/ -name notes.txt
command will search for a file called notes.txt
within the home directory and its subdirectories.
Other variations when using the find
are:
To find files in the current directory use, find -name notes.txt
To look for directories use, / -type d -name notes. txt
Another basic Linux command that is undoubtedly helpful for everyday use is grep
. It lets you search through all the text in a given file.
To illustrate, grep blue notepad.txt
will
search for the word blue in the notepad file. Lines that contain the searched word will be displayed fully.
df
command to get a report on the system’s disk space usage, shown in percentage and KBs. If you want to see the report in megabytes, type df -m
.du
(Disk Usage) command is the answer. However, the disk usage summary will show disk block numbers instead of the-h
argument to the command line.• The head
command is used to view the first
lines of any text file. By default, it will show the first ten lines, but you can change this number to your liking. For example, if you only want to show the first five lines, type head -n 5 filename.ext
.
tail
command will display the last ten lines of a text file. For example, tail -n filename.ext.
Short for difference, the diff
command compares the contents of two files line by line. After analyzing the files, it will output the lines that do not match. Programmers often use this command when they need to make program alterations instead of rewriting the entire source code.
The simplest form of this command is diff file1.ext file2.ext
The tar
command is the most used command to archive multiple files into a tarball
— a common Linux file format that is similar to zip format, with compression being optional.
https://www.linuxtechi.com/17-tar-command-examples-in-linux/
chmod
is another Linux command, used to change the read, write, and execute permissions of files
and directories.
chown
command enables you to change or transfer the ownership of a file to the specified username. For instance, chown linuxuser2 file.ext
will make linuxuser2
as the owner of the file.ext
.jobs
command will display all current jobs along with their statuses. A job is basically a process that is started by the shell.If you have an unresponsive program, you can terminate it manually by using the kill
command. It will send a certain
signal to the misbehaving app and instructs the app to terminate itself.
There is a total of sixty-four-signals that you can use, but people usually only use two signals:
SIGTERM (15)
: requests a program to stop running and gives it some time to save all of its progress. If you don’t specify the signal when entering the kill command, this signal will be used.SIGKILL (9)
: forces programs to stop immediately. Unsaved progress will be lost.
Besides knowing the signals, you also need to know the process identification number (PID) of the program you want to kill
. If you don’t know the PID, simply run the command ps ux
.
After knowing what signal you want to use and the PID of the program, enter the following syntax: kill [signal option] PID
.
ping
command to check your connectivityping google.com
, the command will check whether you’re able towget
command. To do so, simply type wget
followed by the download link.uname
command, short for Unix Name, will print detailed information about your Linux system like the machine name, operating system, kernel, and so on.top
command will display a list of running processes and how much CPU each process uses. It’s very useful to monitor system resource usage, especially knowing which process needs to be terminated because it consumes too many resources.history
command is particularly useful if you want to review the commands you’ve entered before.Hello, my name is John
” into a file called name.txt
, you would type echo Hello, my name is John >> name.txt
zip
command to compress your files into a zip archive, and use the unzip
command to extract the zipped files from a zip archive.If you want to know the name of your host/network simply type hostname
. Adding a -I
to the end will display the IP address of your network.
Hostnamectl
host command is a simple utility for performing DNS lookups. It is normally used to convert names to IP addresses and vice versa. When no arguments or options are given, host command displays a short summary of its command line arguments and options. The syntax is as follows:
host example.com
host -t TYPE example.com
host -t a example.com
https://www.cyberciti.biz/faq/unix-linux-dns-lookup-command/
root@user:~# apt-get update
root@user:~# apt-get install dnsutils –y
Since Linux is a multi-user system, this means more than one person can interact with the same system at the same time. useradd
is used to create a new user, while passwd
is adding a password to that user’s account. To add a new person named John type, useradd John
and then to add
his password type, passwd 123456789
.
To remove a user is very similar to adding a new user. To delete the users account type, userdel UserName
Try the TAB
button to autofill what you are typing
For example, if you need to type Documents, begin to type a command (let’s go with cd Docu
then hit the TAB key) and the terminal will fill in the rest, showing you cd Documents
Ctrl+C
and Ctrl+Z
are used to stop any command that is currently working. Ctrl+C
will stop and terminate the command, while Ctrl+Z
will simply pause the command.
If you accidental freeze your terminal by using Ctrl+S
, simply undo this with the unfreeze Ctrl+Q
.
Ctrl+A
moves you to the beginning of the line while Ctrl+E
moves you to the end
You can run multiple commands in one single command by using the ;
to separate them. For example Command1; Command2; Command3
Or use &&
if you only want the next command to run when the first one is successful.
One of the most powerful tools in the CMD command library is the ASSOC command.
Your computer associates certain file extensions with certain programs. This is how your computer knows to open Adobe when you double click a PDF file, or Microsoft Word when you double click a DOC file.
You can view all the file associations your computer knows about by typing ASSOC
in the command window. You’ll see
the file extension and the program it’s associated with.
You can set the association by typing something like assoc .doc=Word.Document.8
.
Sometimes when files are changed over time, it’s hard to remember what the differences were between versions. You may not know that a CMD command offers the ability to compare files and see all differences, but it’s true.
The FC
command performs either an ascii or a binary file comparison and will list all of the differences that it finds.
Fc /a File1.txt File2.txt
will compare two ascii files.
Fc /b Picture1.jpg Picture2.jpg
will do a binary compare on two images.
IPCONFIG
.This information can help you troubleshoot router issues and other connection issues you could be having with your network adapter.
Examples:
> ipconfig ... Show information
> ipconfig /all ... Show detailed information
> ipconfig /renew ... renew all adapters
> ipconfig /renew EL* ... renew any connection that has its name starting with EL
> ipconfig /release *Con* ... release all matching connections, eg.
"Wired Ethernet Connection 1" or "Wired Ethernet Connection 2"
> ipconfig /all
compartments ... Show information about all compartments
> ipconfig /all
compartments /all ... Show detailed information about all compartments
/?
Display this help message
/all
Display full configuration information.
/release
Release the IPv4 address for the specified adapter.
/release6
Release the IPv6 address for the specified adapter.
/renew
Renew the IPv4 address for the specified adapter.
/renew6
Renew the IPv6 address for the specified adapter.
/flushdns
Purges the DNS Resolver cache.
/registerdns
Refreshes all DHCP leases and re-registers DNS names
/displaydns
Display the contents of the DNS Resolver Cache.
/showclassid
Displays all the dhcp class IDs allowed for adapter.
/setclassid
Modifies the dhcp class id.
/showclassid6
Displays all the IPv6 DHCP class IDs allowed for adapter.
/setclassid6
Modifies the IPv6 DHCP class id.
NETSTAT
command in theAn IT Analyst’s best friend is the PING
command.
Running this command sends test packets over the network to the target system.
You can use the PING
command to test whether your computer can access another computer, a server, or even a website. It can help with revealing network disconnections. It also provides transit time for the packets in milliseconds,
so it also reveals a bad network connection as well.
POWERCFG
(power configuration) that can help.Run the command prompt as an administrator and
type
powercfg – energy
to get a full power efficiency report.
The process can take up to about a minute, but when it’s done, you’ll see whether there are any warnings or errors that might help you improve the power efficiency of your system.
The SHUTDOWN
command is a pretty versatile command that lets you shutdown the computer but control the behavior
of that shutdown. It’s commonly used as a scheduled task or part of an IT batch job after patches have been applied to a computer system.
Typing shutdown /i
from the command prompt will initiate a shutdown, but it’ll upon a GUI to give the user an option on
whether to restart or do a full shutdown. If you don’t want to have any GUI pop up, you can just issue a shutdown /s
command.
There is a long list of other parameters you can use to do a log off, hibernate, restart, and more. Just type shutdown
without any arguments to see them all.
If you need to know what brand of network card you have, processor details, or the exact version of your Windows OS, the SYSTEMINFO
command can help.
This command polls your system and pulls the most important information about your system. It lists the information in a clean format that’s easy to read.
If you’re ever concerned that a virus or some other software might have corrupted your core system files, there’s a Windows command that can scan those files and
ensure their integrity.
You need to launch CMD as administrator (right click and choose Run as Administrator). Typing SFC /SCANNOW
will check the integrity of all protected system files. If a problem
is found, the files will be repaired with backed-up system files.
/VERIFYONLY
: Check the integrity but don’t repair the files./SCANFILE
: Scan the integrity of specific files and fix if corrupted./VERIFYFILE
: Verify the integrity of specific files but don’t repair them./OFFBOOTDIR
: Use this to do repairs on an offline boot directory./OFFWINDIR
:/OFFLOGFILE
: Specify a path to save a log file with scan results.If you want to map a new drive, you could always open File Explorer, right click on This PC, and go through the Map Network Drive wizard. However, using the NET USE
command, you can do the same thing with one command string.
For example, if you have a share folder on a computer on your network called \\OTHER-COMPUTER\SHARE\
, you can
map this as your own Z:
drive by typing the command:
NET USE Z: “\\OTHER-COMPUTER\SHARE” /persistent:yes
The persistent
switch tells your computer that you want this drive remapped every time you log back into your computer.
CHKDSK /f C:
.Windows comes with a wizard for creating scheduled tasks. For example, maybe you have a BAT file stored on C:\temp that you want to run every day at noon.
You’d have to click through the Scheduled Task wizard to configure this. Or you can type a single SCHTASKS command to set it up.
SCHTASKS /Create /SC HOURLY /MO 12 /TR Example /TN c:\temp\File1.bat
The scheduled switch accepts arguments like minute, hourly, daily, and monthly. Then you specify the frequency with the /MO command.
If you typed the command correctly, you’ll see the response, SUCCESS: The scheduled task “Example” has successfully been created.
ATTRIB +R +H C:\temp\File1.bat
, it’ll set File1.bat as a hidden, read-only file.BITSADMIN
: Initiate upload or download jobs over the network or internet and monitor theCOLOR
: Change the background color of the command prompt window.COMP
: Compare the contents of any two files to see the differences.FIND/FINDSTR
: Search for strings inside of any ASCII files.PROMPT
: Change the command prompt from C:> to something else.TITLE
: Change the title of the command prompt window.REGEDIT
: Edit keys in the Windows registry (use with caution).ROBOCOPY
: A powerful file copy utility built right into Windows.