Basic Linux Command Sharing - Part1

1
2
3
4
Content:
1. How to find file/directory
2. How to move, copy or delete file/directory
3. How to find keyword in specific file/directory

How to find file/directory

1
find ./ -name "*.git" -type d

  • find file: type f
  • find directory: type d

How to move, copy or delete file/directory

1
find ./ -name "*.git" -type d | xargs -i mv {} source
  • move the directory, ‘.git’, to ‘source’
1
file * | grep "source" | awk '{print $1}' | cut -d':' -f1 | xargs ls | xargs -i mv {} C/
  • find “source” and move to “C” directory
1
find ./ -name "*.git" -type -d | xargs -i cp {} source
  • copy directory, ‘*.got’, to ‘C’ directory
1
find ./ -name "*.git" -type -d | xargs rm
  • remove directory, ‘*.got’

How to find keyword in specific file/directory

1
find ./ -name "*.git" -print0 | xargs -0 grep -r "main" --color
1
find ./ -name "*.git" -print0 | xargs -0 ag "main"
© 2022 Tiffany's Blog All Rights Reserved. 本站访客数人次 本站总访问量
Theme by hiero