Сценарии практического занятия на тему: Работа с файлами в UNIX
«Вопросы»
- pwd
- cd /
- ls
- ls -F
- ls ~
- cd
- mkdir test
- ls
- mkdir test/subtest
- ls -R
«Вопросы»
- touch first.txt
- echo
- echo "Hello, world" >> first.txt
- cat first.txt
- ls
- alias ls='ls -F -l'
- ls
- cp first.txt copy1.txt
- mv first.txt orig.txt
- mv first.txt orig.txt
- ln orig.txt copy2.txt
- ln -s orig.txt orig.lnk
«Вопросы»
- find
- find -name "o*"
- find /etc
-name "o*"
- find /etc -name "o*" 2>/dev/null
- find /etc -name "o*" -a -type d 2>/dev/null
- mkdir logs
- find /var -name "*log" -a -type f -exec cp {} test/logs/ 2>/dev/null
«Вопросы»
- cd
- tar -czf test.tar.gz test
- mkdir test2
- cd test2
- tar -xzf ../test.tar.gz
- ls -l -a -F
«Вопросы»
- cd ~/test
- echo "One line"
- echo "One line" > second.txt
- echo "A line" >>
second.txt
- cat second.txt
- cat > multiline.txt
- cat multiline.txt
- cat orig.txt second.txt
multiline.txt > big.txt
- cat big.txt
«Вопросы»
- cat /etc/passwd
- cat /etc/passwd | cut -f1 -d:
- cat /etc/passwd | cut -f1 -d: | sort
- cat /etc/passwd | cut -f7 -d:
- cat /etc/passwd | cut -f7 -d: | uniq
- sort
- cat /etc/passwd | cut
-f7 -d: | sort | uniq
- cat /etc/passwd | cut -f1 -d: > users
- cat /etc/passwd | cut -f7 -d: > shells
- paste users shells
«Вопросы»
- wc -l /etc/passwd
- cat users | wc -w
- head logs/Xorg.0.log
- tail logs/Xorg.0.log
«Вопросы»
- less test/logs/Xorg.0.log
- grep "^(WW)" test/logs/Xorg.0.log
- grep "[a-zA-z0-9]\+@[a-zA-z0-9\.]\+\.[a-z]\{2,4\}" /etc/* 2>/dev/null
- grep
- grep -h "[a-zA-z0-9]\+@[a-zA-z0-9\.]\+\.[a-z]\{2,4\}" /etc/*
2>/dev/null
- grep
-ho "[a-zA-Z0-9]\+@[a-zA-Z0-9\.]\+\.[a-z]\{2,4\}" /etc/* 2>/dev/null
- find /etc -type f 2>/dev/null
- find
/etc -type f -exec grep "nameserver" {} \; 2>/dev/null
- find /etc -type f -exec grep -Hn
"nameserver" {} \; 2>/dev/null