Mostrando postagens com marcador Unix. Mostrar todas as postagens
Mostrando postagens com marcador Unix. Mostrar todas as postagens

sexta-feira, 28 de junho de 2019

Unix Command - How to rename much files in directory to fixing filename?

Using shellscript with awk to change filename.

Wrong filename.: 0400000000192062019.zip
Wanted filename: 04000000001920062019.zip

First, create a mask to list files:


>$ ls -1 ????????????2062019.zip ????????????2062019.zip.fin

0400000000192062019.zip


0400000000192062019.zip.fin

Second, create a loop to work with filenames:


>$ for x in $(ls -1 ????????????2062019.zip ????????????2062019.zip.fin); do echo $x; done
0400000000192062019.zip

0400000000192062019.zip.fin

And next, using AWK to fix filename:

Testing

>$ for x in $(ls -1 ????????????2062019.zip ????????????2062019.zip.fin ); do new=$(awk 'BEGIN{file=ARGV[1]; print substr(file,1,14) "0" substr(file,15)}' $x); echo "changing filename $x to $new"; done

changing filename 0400000000192062019.zip to 04000000001920062019.zip
changing filename 0400000000192062019.zip.fin to 04000000001920062019.zip.fin


Fixing
>$ for x in $(ls -1 ????????????2062019.zip ????????????2062019.zip.fin ); do new=$(awk 'BEGIN{file=ARGV[1]; print substr(file,1,14) "0" substr(file,15)}' $x); echo "changing filename $x to $new"; mv $x $new; done

changing filename 0400000000192062019.zip to 04000000001920062019.zip
changing filename 0400000000192062019.zip.fin to 04000000001920062019.zip.fin


quinta-feira, 8 de maio de 2014

VIM: using accent in portuguese

How you can see and use accent in VIM for portuguese language?
Como ver e usar acentuação no VIM para língua portuguesa?

Have two way to do this in *Unix.

1. In Bash profile (~/.bashrc), set the environment variable LANG to latin1 or one of this below:

  • latin1
  • pt_BR.UTF-8
  • iso-8859-1
  • utf-8


2. In VIM profile (~/.vimrc)

  • set encoding=latin1
  • set fileencodings=latin1
  • set termencoding=latin1
  • set nocompatible


You can test in terminal to see if it is ok:

in bash:
    export LANG=latin1
    vim
    write something with accent (e.g. Português)

in vim:
    :set encoding=latin1
    write something with accent (e.g. Português)


terça-feira, 1 de abril de 2014

C++ - Opening a windows with the man page for the word under the cursor - VIM

How to get help when stay developing in VIM?
Como obter ajuda quando estiver desenvolvendo em VIM?

Put the cursor at the word that you want and click "shift + k", the man page of specific command will open
Coloque o cursor na palavra que deseja e click "shift + k", a página do comando específico irá abri

Is the same that you do in command line:


    man 3 <word>

Section of man page on Unix:


Section
Description
1
General commands
1M
System administration commands and daemons
2
System calls
3
C library functions
4
File formats and conventions
5
Miscellanea
6
Games and screensavers
7
Special files (usually devices, those found in /dev) and drivers







Unix Command - How to see library dependencies of programs? - ldd

Viewing library dependencies of programs in Unix with ldd:

command:

     ldd <path_of_binary>


We would see something like this:


 ldd /bin/grep

        linux-vdso.so.1 =>  (0x00007fffad1ff000)
        libpcre.so.0 => /lib64/libpcre.so.0 (0x00000032fe600000)
        libc.so.6 => /lib64/libc.so.6 (0x00000037eaa00000)
        /lib64/ld-linux-x86-64.so.2 (0x00000037ea600000)




The environment var to load the library is LD_LIBRARY_PATH whether some library was not loaded.

terça-feira, 25 de março de 2014

Unix Command - How can you get the subdirectories of an existing directory in *Unix? - find


You can use the find command in *Unix.

Go to the directory that you want to get the subdirectories and do this command:

 find . -type d 


Types:
   d - directory
   f - file
   l - symbolic link


----------------------

other way:

In the directory that you want, do this command:

 ls -ltr | grep ^d 

*this command does not get all existing subdirectories.

terça-feira, 18 de março de 2014

Oracle - How to copy a table to another server?

You can copy a table to another server/database, in Oracle, using this command:

Sqlplus:
 SQL> COPY FROM username1/password1@tnsname1 
           TO username2/password2@tnsname2
      INSERT table_name (*) USING (SELECT * FROM table_name); 


Other way is using dump file in Unix:

Export:
 exp username/password@tnsname FILE=filename.dmp \
    TABLES=owner.table_name COMPRESS=y  


Import:
 impdp username/password dumpfile=filename.dmp 

terça-feira, 25 de fevereiro de 2014

Unix Command - connecting from one server to another - ssh


Como conectar de um servidor em outro?
How to connect from one server to another?

 - *Unix:  utilize este comando:
 - *Unix:  you can do this command:

   ssh -l login remote_ip
 ou
   ssh login@remote_ip 
   ssh -l guest 192.168.0.15 
 ou
   ssh guest@192.168.0.15  

-l  especifica o usuário para logar no servidor remoto
     specifies the user to log in as on the remote machine
    

segunda-feira, 17 de fevereiro de 2014

Unix Command - How to replace some text with another - sed

Para substituir um texto por outro
To replace some text with another

*Unix:

input file:
file_name.txt
this is the text test

command:

sed 's/text/another/g' file_name.txt > new_file_name.txt 

result:

new_file_name.txt

this is the another test


quinta-feira, 13 de fevereiro de 2014

Bash and VIM profile (.bashrc and .vimrc)

Configurando um profile Bash no Linux/Unix
Configuring a Bash profile in Linux/Unix

 - *Unix

Quando iniciar o Bash o profile será carregado através do .bashrc
When start the Bash, the profile will be loaded from .bashrc

$HOME/.bashrc
PS1='[\[\033[01;36m\]\h\[\033[00m\]:\[\033[01;32m\]$(pwd)\[\033[00m\]]\$ '
#if you have VIM installed another place
#export VIM="/home/guest/sfw/share/vim"
 

#set defaults
export EDITOR="vim"
export PAGER="less"
export TERM="xterm"
 

alias ls="ls -h --color=auto --time-style='+%Y-%m-%d %H:%M'"
alias vi="vim"

Quando iniciar o VIM, o profile será carregado através do .bashrc
When start the VIM, the profile will be loaded from .vimrc

 $HOME/.vimrc
syntax on
colorscheme evening
set background=dark
set nu
set autoindent
set ts=3 " Quantidade de espaço do TAB
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%04l,%04v][%p%%]\ [LEN=%L] " Define as informações da barra de status.
set laststatus=2 " Exibe a barra de status.
hi statusline term=bold cterm=bold ctermfg=7 ctermbg=4 " Define a cor da barra de status.
set hlsearch " realça a pesquina encontrada
set incsearch " realça o texto da pesquisa
set backspace=indent,eol,start " Permite que o backspace apague em modo de insert

"acentuação em 
Português no vim - iso-8859-1. latin1, utf-8, pt_BR, pt_BR.UTF-8
"no bash: export LANG=latin1
set encoding=latin1
set fileencodings=latin1
set nocompatible
set termencoding=utf-8

* To change the home directory: export HOME="/new/directory"

segunda-feira, 10 de fevereiro de 2014

Unix Command - controlling processes with screen manager - screen

Como controlar processos de modo eficiente?
How to control processes efficiently?

 - *Unix:  utilize este comando:
 - *Unix:  you can do this command:

 screen -LdmS session_name command 
 screen -LdmS m_vi man vi
-L ligar o registro de log das janelas (arquivo: screenlog.0)
-d iniciar em segundo plano
-m ignorar as variáveis de ambiente $STY
-S especificar o nome da sessão

-L to turn on automatic output logging for the windows (file: screenlog.0)
-d to start in "detached" mode
-m to ignore the $STY environment variable
-S to specify a meaningful name for the session

Listar os nomes das sessões:
Print a list of strings identifying your sessions:

 screen -ls 
*a sessão listada possui pid.nome_da_sessão
*the session listed have pid plus session name
**pid = process ID (numeric)

Limpar as sessões mortas:
To clean the killed session:

 screen -wipe 
*pode usar kill -9 pid e depois screen -wipe
*you can do kill -9 pid and then screen -wipe 

Recuperar uma sessão:
To resume a detached screen session:

 screen -r session_name 

Enviar para segundo plano a sessão recuperada:
To detach the session from the terminal:

 ctrl+a d 



Unix Command - copying file from remote server

Como copiar arquivo de um servidor remoto?
How to copy a file from remote server?

 - *Unix:  utilize este comando:
 - *Unix:  you can do this command:

 scp login@ip_remote:/remote_dir/file /target/ 

Copiar os subdiretórios recursivamente:
Recursively copies entire directories:

 scp -r login@ip_remote:/remote_dir/* /target/ 

Habilitar compressão:
Enable compression:

 scp -o 'CompressionLevel 9' -C \
  login@ip_remote:/remote_dir/* /target/ 

Outro jeito:
Another way:

 cd /target/

 ssh -o 'CompressionLevel 9' -C -l login ip_remote
  'cd /remote_dir; tar cpvf - remote_dir_or_file'  \ 
  | tar xpfv -  



sexta-feira, 7 de fevereiro de 2014

Unix Command - estimate file space usage - du

Como identificar o tamanho dos diretórios, exibindo apenas o total de cada um?
How can we get the size of directory, displaying only a total for each one?

 - *Unix:  utilize este comando:
 - *Unix:  you can do this command:

 du -hs * 

Idenfiticar qual diretório com maior tamanho:
To identify which directory is greater:

 du -hs * | sort -hr 

Unix Command - compare files line by line - diff


Como comparar dois arquivos em servidores diferentes?
How you can compare two files in different servers?

 - *Unix:  utilize este comando:
 - *Unix:  you can do this command:

 ssh login@remote_ip "cat ~/remote_filename"|diff ~/local_filename
 ssh guest@192.168.0.15 "cat ~/.profile" | diff ~/.profile -