Counting number of folders or files in a specific directory
Using find
command
find /directory/ -maxdepth 1 -type d -print | wc -l
The additional 1 count is there due the the current directory ‘.’ , which is also taken into account by find
, i.e. , find
is also printing the directory itself.
$ find /home/dir/ -maxdepth 1 -type d -print | wc -l
12345
So the number of files in the /home/dir/
is 12344.
For more info, please go to this
Copy the folder to another folder
$ cp -r source_path destination_path
Compile c++ files in terminal
Suppose your source code name is main.cpp:
g++ main.cpp -o main
- g++ is the invocation of the C++ component of GCC, the defacto compiler for C/C++ and whole host of other languages on the Linux platform. It’s currently the only compiler capable of compiling the Linux kernel.
- main.cpp is the c++ source file you wish to compile.
- -o main specifies the name of the output file you wish to create once the source is compiled. The target source file and the target output file can be inverted if you wish, so g++ -o main main.cpp is equally valid.
- To then execute that program, you need to do
./main
in the terminal.