Editing
Basic Linux Commands
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Examples == === <span id="ex-pwd"></span>Print Working Directory === <syntaxhighlight lang="bash"> pwd # Output: # /home/user </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-cd"></span>Change Directory === <syntaxhighlight lang="bash"> cd /var/www # Output: # (no output) </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-sed"></span>Substitute Text in String === <syntaxhighlight lang="bash"> echo "Hello world" | sed 's/world/Linux/' # Output: # Hello Linux </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-ls"></span>List All Files (long + hidden) === <syntaxhighlight lang="bash"> ls -la # Output: # total 12 # drwxr-xr-x 3 user user 4096 May 16 22:15 . # drwxr-xr-x 18 user user 4096 May 16 21:00 .. # -rw-r--r-- 1 user user 0 May 16 22:15 index.html </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-mkdir"></span>Create Directory === <syntaxhighlight lang="bash"> mkdir backups # Output: # (no output) </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-rmdir"></span>Remove Empty Directory === <syntaxhighlight lang="bash"> rmdir backups # Output: # (no output) </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-cp"></span>Copy File === <syntaxhighlight lang="bash"> cp secrets.txt /tmp/secrets.bak # Output: # (no output) </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-mv"></span>Move & Rename === <syntaxhighlight lang="bash"> mv old.log archive/old.log # Output: # (no output) </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-rm"></span>Force-Delete Directory === <syntaxhighlight lang="bash"> rm -rf /tmp/testdir # Output: # (no output) </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-cat"></span>Show File Contents === <syntaxhighlight lang="bash"> cat /etc/passwd | grep ":/bin/bash" # Output: # root:x:0:0:root:/root:/bin/bash # user:x:1000:1000:User,,,:/home/user:/bin/bash </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-less"></span>View Large Log === <syntaxhighlight lang="bash"> less /var/log/auth.log # Output: # (opens file in pager; press q to quit) </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-head"></span>First 10 Lines === <syntaxhighlight lang="bash"> head -n 10 notes.txt # Output: # Line 1 # Line 2 # Line 3 # Line 4 # Line 5 # Line 6 # Line 7 # Line 8 # Line 9 # Line 10 </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-tail"></span>Follow File Growth === <syntaxhighlight lang="bash"> tail -f /var/log/nginx/access.log # Output: # 192.168.1.5 - - [16/May/2025:22:30:01 +0200] "GET / HTTP/1.1" 200 1234 # 192.168.1.5 - - [16/May/2025:22:30:02 +0200] "GET /favicon.ico HTTP/1.1" 404 564 </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-grep"></span>Search Pattern === <syntaxhighlight lang="bash"> grep -R "passwd" /etc # Output: # /etc/login.defs:PASS_MAX_DAYS 99999 # /etc/pam.d/common-password:password requisite pam_pwquality.so retry=3 </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-whoami"></span>Current User === <syntaxhighlight lang="bash"> whoami # Output: # user </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-id"></span>User & Group IDs === <syntaxhighlight lang="bash"> id # Output: # uid=1000(user) gid=1000(user) groups=1000(user),27(sudo) </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-df"></span>Human-Readable Disk Usage === <syntaxhighlight lang="bash"> df -h # Output: # Filesystem Size Used Avail Use% Mounted on # /dev/sda1 30G 12G 17G 42% / </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-history"></span>Show Last 20 Commands === <syntaxhighlight lang="bash"> history | tail -n 20 # Output: # 981 ls # 982 cd /var/www # 983 vim index.html # ... # 1000 exit </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-ping"></span>Ping Host 4 Times === <syntaxhighlight lang="bash"> ping -c 4 example.com # Output: # PING example.com (93.184.216.34) 56(84) bytes of data. # 64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=12.3 ms # 64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=12.1 ms # 64 bytes from 93.184.216.34: icmp_seq=3 ttl=56 time=12.0 ms # 64 bytes from 93.184.216.34: icmp_seq=4 ttl=56 time=12.2 ms # --- example.com ping statistics --- # 4 packets transmitted, 4 received, 0% packet loss, time 3005ms # rtt min/avg/max/mdev = 12.012/12.173/12.325/0.123 ms </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-curl"></span>Download Web Page === <syntaxhighlight lang="bash"> curl -o index.html http://example.com # Output: # % Total % Received % Xferd Average Speed Time Time Time Current # Dload Upload Total Spent Left Speed # 100 1270 100 1270 0 0 2500 0 --:--:-- --:--:-- --:--:-- 2500 </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-ssh"></span>SSH on Custom Port === <syntaxhighlight lang="bash"> ssh -p 2222 user@target # Output: # The authenticity of host 'target (192.168.1.50)' can't be established. # ED25519 key fingerprint is SHA256:abc123... # Are you sure you want to continue connecting (yes/no/[fingerprint])? </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-man"></span>Read Manual Page === <syntaxhighlight lang="bash"> man ssh # Output: # (opens manual page; press q to quit) </syntaxhighlight> ''[[#commands|β Commands]]'' === <span id="ex-echo"></span>Write to File === <syntaxhighlight lang="bash"> echo "hacked" > /tmp/proof.txt # Output: # (no output) </syntaxhighlight> ''[[#commands|β Commands]]''
Summary:
Please note that all contributions to HackOps may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
HackOps:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Search
Navigation
Tools
What links here
Related changes
Special pages
Page information