search, view and permissions
Searching & viewing files
cat file.txt # Display entire fileless file.txt # View file page-by-page (q to quit)head file.txt # First 10 linestail file.txt # Last 10 linestail -f /var/log/somelog # Follow log file in real-time (crucial!)grep "search term" file.txt # Find text in filegrep -r "search term" /path/ # Search recursively through directoriesfind /path -name "filename" # Find files by namePermissions and ownership
chmod +x script.sh # Make file executablechmod 644 file.txt # Read/write for owner, read for otherschmod 755 script.sh # Common for executable fileschown user:group file.txt # Change file ownersudo command # Run as root (superuser)Understanding chmod numbers (it’s like a whole another mini language, fun times)
- 4 = read, 2 = write, 1 = execute
- First digit = owner, second = group, third = everyone
- So 755 = owner(7=4+2+1=rwx), group(5=4+1=rx), others(5=4+1=rx)
More will be expanded on this later on - still don’t fully get it myself :)