Utilities to manage Files and Directories


AIX Commands for Managing files and directories

  • cd Change directory
  • ls Display the content of a directory
      • ls -la Display the content of a library long format
      • ls -latr Display the content of a library in chronogical order
  • cat Display, create, copy, concat a file
    • cat file.input Display file.input
    • cat file1.input file2.input > file.outpout Concat file1 et file2
  • more Display each page of a file
  • cp  Copy files or directories
  • mv Move or rename file
  • grep Search a string in a file
    • grep -r "text" /tmp Search the string text in the /tmp directory
  • wc Count word, line in a file
  • ln Make a hard or soft link of a file
  • touch Create an empty file
  • find Find a file
    • find . -name "text.txt" Find the file text.txt
    • find . -name "*.txt" | xargs -n1 ls -la Find the files *.txt if there is too many occurences 
    • find . -name "text*" | xargs rm Find all the file with the argument text* and remove it
    •  find . -type f -mtime +10 | xargs -n1 rm Find all files older than 10 days and remove it
  • chmod Modify the permission of a file or directory
    • chmod ugo+rwx Set the permission for user - group - other + Read - Write - execute
  • chown Change the owner of a file or directory
    • chown user file
  • chgrp Change the group of a file or directory
    • chgrp group file
  • cut Cut certain colonn of a file
  • head Display the head of a file
  • sdiff Display the difference between two files
  • sort Sort the content of a file
  • tail Display the last lines of a file
    • tail -f /var/log/error.log Display in "real time" the content of a log file
  • mkdir Make a directory
  • rmdir Remove a directory
  • nl Number lines in a file
    • nl -ba file.txt

AIX utlitites - Transforming and converting files

 Here are listed some "utilities" with example to transform files.
  • tr
    • tr '\332' '012'< file.input > file.output To transform character 'DA' (hex) to '0A' (hex). The value 332 and 012 are in octal
    • tr -d '\025' < file.input > file.output To delete the character '15' (hex). The value 025 are in octal
    • tr 'A-Z' 'a-z' < file.input > file.output To transform upercase to lowercase
    • tr 'àçéèêëîïôöùüÂÇÉÈÊËÎÏÔÖÙÜ' 'aceeeeiioouuACEEEEIIOOUU' < file.input > file.output
  • sed
    • sed
  • perl
    • perl -pe 's/\332/\012/g' < file.input > file.output To transform character 'DA' (hex) to '0A' (hex). The value 332 and 012 are in octal
    • perl -pe 's/\332/\015\012/g' < file.input > file.output To transform character 'DA' (hex) to '0D0A' (hex. Thel value 332, 015 and 012 are in octal.
    • perl -n -e 'chop; printf "%-120s\n",$_;'  < file.input > file.output To transform a file with a Carriage Return at the position 120
    • perl -e '1,2d' < file.input > file.output To suppress the first two line of a file
    • perl -e 'while (read(STDIN, $l, 160)){printf "%s\n",$l;}' < file.input >file.output To add a carriage return at the position 160
  • iconv To convert from one encoding to another encoding
      • iconv -f ISO8859-1 -t IBM-850 file.input > file.output To convert file from ISO8859-1 to IBM-850 encoding
  • awk
    • ls -la * | tail -1 | awk '{print $9}' To display information of the colon 9 in a ls command
    • ls -ltr | grep "Jan 24" | awk '{print $9}' | xargs -n1 -i cp {} /work/toto/
  • dd
    • dd if=/tmp/file.input of=/tmp/file.output conv=ascii To convert input file from bin to ascii
  • Sript to transform "dos file" to Unix (in particular ^M)
    • #!/usr/bin/ksh

      if [ $# -ne 1 ]
      then
      echo "Usage: $0 filename"
      exit
      fi

      sed 's/^M$//' $1 > tmp
      mv tmp $1
      chmod 755 $1
  • Tips to transform Dos file to Unix
    • # to convert DOS file to Unix in place:
      • perl -i -pe 's/\r//g' file
    • # Unix to DOS:
      • perl -pe 's/$/\r/g' < infile > outfile
    • # Unix to DOS in place:
      • perl -i -pe 's/\n/\r\n/' file
    • # to check for <CR> :
      • perl -ne 'print if /\r/' < infile




What Others are Reading Now...

0 Comment to "Utilities to manage Files and Directories"

Post a Comment