This list of commands came from a txt of notes of mine. I thought it would be useful to publish it, especially for students who are new to the Mac terminal. The idea is to gradually add more commands.
As Bertoldo would say:
– Type it in!!! (in portuguese: Digita aí!!!! ) 🙂
1. Display current directory.
$ pwd
/Users/adrianotavares
2. Change to home directory.
$ cd ~
3. List files with details including hidden files.
$ ls -la
total 0
drwxr-xr-x 6 root admin 204 24 Out 2014 .
drwxr-xr-x 40 root wheel 1428 3 Jul 21:11 ..
-rw-r--r-- 1 root wheel 0 9 Set 2014 .localized
drwxr-xr-x+ 11 Guest _guest 374 24 Out 2014 Guest
drwxrwxrwt 9 root wheel 306 2 Mai 09:52 Shared
drwxr-xr-x+ 89 adrianotavares staff 3026 6 Jun 19:20 adrianotavares
4. List all running processes.
$ ps -acx
PID TTY TIME CMD
1 ?? 0:10.13 launchd
39 ?? 0:01.14 syslogd
40 ?? 0:00.86 UserEventAgent
...
690 ttys000 0:00.07 login
691 ttys000 0:00.04 -bash
731 ttys000 0:00.00 ps
5. Find out the number of a running process.
$ ps -acx | grep eclipse
748 ?? 0:24.14 eclipse
6. Find out the number and command line of a running process.
$ ps aux | grep eclipse
adrianotavares 748 1,3 5,8 4716148 485956 ?? S 10:29 1:01.73 /Users/adrianotavares/eclipse/Eclipse.app/Contents/MacOS/eclipse
adrianotavares 822 0,0 0,0 2432772 632 s000 S+ 10:34 0:00.00 grep eclipse
7. Kill running process.
$ kill 748
8. Copy files to home.
$ cp *.txt ~
9. Remove txt files.
$ rm *.txt
10. View the contents of a file.
$ less server.sh
#!/bin/sh java -server -Xms128M -Xmx256M -Djava.net.preferIPv4Stack=true -cp ../lib/hazelcast-3.2.6.jar com.hazelcast.examples.StartServer server.sh (END)
11. View Log file scrolling.
$ tail -f hazelcast.log
12. View memory and CPU usage.
$ top
Processes: 235 total, 5 running, 5 stuck, 225 sleeping, 1090 threads 00:56:31
Load Avg: 1.67, 2.27, 2.49 CPU usage: 19.43% user, 13.27% sys, 67.29% idle
SharedLibs: 14M resident, 13M data, 0B linkedit.
MemRegions: 54019 total, 3834M resident, 134M private, 718M shared.
PhysMem: 7712M used (1085M wired), 478M unused.
VM: 573G vsize, 1063M framework vsize, 0(0) swapins, 0(0) swapouts.
Networks: packets: 1012422/1404M in, 782553/397M out.
Disks: 129198/3468M read, 144948/3718M written.
PID COMMAND %CPU TIME #TH #WQ #PORT MEM PURG CMPR PGRP PPID
1226 top 3.6 00:00.55 1/1 0 19 2248K 0B 0B 1226 963
1216 com.apple.iC 0.0 00:00.19 2 0 45 1972K 0B 0B 1216 1
1178 mdworker 0.0 00:00.03 3 0 41 1548K 0B 0B 1178 1
1171 Google Chrom 0.7 00:18.87 10 0 100 115M+ 0B 0B 1068 1068
1168 Google Chrom 0.0 00:01.63 8 0 99 65M 0B 0B 1068 1068
1167 mdworker 0.0 00:00.14 4 0 52 7696K 0B 0B 1167 1
1162 mdworker 0.0 00:00.17 4 0 52 7156K 0B 0B 1162 1
1149 mdworker 0.0 00:00.12 4 0 52 6764K 0B 0B 1149 1
1146 mdworker 0.0 00:00.06 2 0 39 1440K 0B 0B 1146 1
1145 mdflagwriter 0.0 00:00.00 2 1 18 492K 0B 0B 1145 1
1144 mdworker 0.0 00:00.04 3 0 41 1528K 0B 0B 1144 1
1138 tccd 0.0 00:00.01 2 1 26 840K 0B 0B 1138 1
1137 AssetCacheLo 0.0 00:00.15 4 0 75 2648K 0B 0B 1137 1
1135 softwareupda 0.0 00:02.75 7 4 96 2296K 0B 0B 1135 1
13. Get the current date.
$ date
Sáb 4 Jul 2015 01:13:08 BRT
14. List logged in users.
$ who
adrianotavares console Jul 3 21:04
adrianotavares ttys000 Jul 3 23:30
15. To run multiple commands on the same line, use a semicolon ( ; ).
$ pwd;who;date
/Users/adrianotavares
adrianotavares console Jul 3 21:04
adrianotavares ttys000 Jul 3 23:30
Sáb 4 Jul 2015 01:26:14 BRT
16. Display the value of an environment variable.
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
17. Create an empty file.
$ touch myfile.txt
18. Edit file.
$ vi myfile.txt
Test my file.
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"myfile.txt" 1L, 19C
To write in vi.
- esc, i : insert character
- delete : delete character
- esc, d, d : delete line
- esc :wq! saves and exits
- esc :q! exits without saving
19. Calculate the size of a file.
$ du myfile.txt
8 myfile.txt
20. Calculate the size of a directory.
$ du -s -h Downloads
17G Downloads
21. Calculate available disk space.
$ df h
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk0s2 232Gi 220Gi 12Gi 95% 57724162 3115580 95% /
devfs 180Ki 180Ki 0Bi 100% 622 0 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% 0 0 100% /net
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /home
22. Change file permission.
$ chmod 777 myfile.txt; ls -la myfile.txt
-rwxrwxrwx 1 adrianotavares staff 26 4 Jul 01:47 meuarquivo.txt
23. Change the current user’s password.
$ passwd Changing password for adrianotavares. Old Password: New Password: Retype New Password:
If anyone wants to help me with olther commands and scripts, comment below and I’ll add it to the list.
