Skip to main content

[Linux] miscellaneous

Create directory tree in linux using C plusplus

Example is not correct at all when it handle "status"
it should be:
#include <bits/stdc++.h>
#include <iostream>
#include <sys/stat.h>
#include <sys/types.h>
using namespace std;
int main() {
   int status;
   status = system("mkdir -p TP/My_Folder/test"); // Creating a directory
   if (status != 0)
      std::cerr << "Error : " << strerror(errno) << std::endl;
   else
      std::cout << "Directories are created" << std::endl;
}

What is default permission of command  "system("mkdir -p TP/My_Folder/test");"?
The answer is 755 or drwxr-xr-x

What is drwxr-xr-x?
It looks like 4 groups:  d  rwx  r-x  r-x
d: directory (file is "-")
rwx: owner can read/write/execute
r-x:  group user can read/execute
r-x:  other user can read/execute
Bonus: "-" is permission not set

What is "755"
ref: https://www.maketecheasier.com/file-permissions-what-does-chmod-777-means/

0 – no permission
1 – execute
2 – write
3 – write and execute
4 – read
5 – read and execute
6 – read and write
7 – read, write, and execute

Example: Try to create some directories and show default permission by command "ls"

Bonus ++: You may concern about command chmod options as below

Example:
1. Allow one file is run by user(owner)
chmod u+x runablefile.sh

2. Allow full permission with one file for group of user
chmod g+rwx groupfull.txt

The man page of chmod covers that.
u stands for user.
g stands for group.
o stands for others.
a stands for all.


Comments

Popular posts from this blog

[Git] Handle trailing space when patching with git

After complete coding one module in development branch. Next phase is merging. Obviously, you can merge source code automatically without no errors happen. However, life is not dream. Create a patch git diff HEAD > newTariff.patch Apply patch git apply newTariff.patch then problem happens Problem git apply newTariff.patch:106: trailing whitespace. patch does not apply Route cause: Nguyên nhân: Do trong source code có những dấu space thừa (ô vuông màu đỏ hình dưới) Some whitespaces is existed in your patch. (red area in below pictures) Fix Clean white space and patch again. Cách khắc phục Xóa những dấu space này đi và thực hiện patch lại Make up after complete coding. Find and clean whitespace before create patch file. Sửa sau khi code xong Kiểm tra sau khi code xong có lỗi này không git diff HEAD --check Prevent whitespace by manually when typing source code Sửa ngay khi đang code =>Bật chức năng hiển thị các dấu whitespace, hoặc remove trailing ...

How to test frame buffer in linux

The intended goal of this article is to provide the user with enough information so they can display an image onto a screen of their choosing. How to re-build frame buffer testing application. Base knowledge http://trac.gateworks.com/wiki/OpenEmbedded/Video_Out Frame buffer test application - rebuild fb-test-app step 1: Download soure code ( git installed on your machine and account in git-hub is required) https://github.com/prpplague/fb-test-app Command in git: git init git clone https://github.com/prpplague/fb-test-app.git step 2: Change makefile vi Makefile //open Makefile by vim editor :set nu //show line number replace from line 6 to line 12 by folow code: CC=arm-linux-gnueabi-gcc CFLAGS=-02 -Wall Save change command :wq step 3: Rebuid Type “make” command step 4: Copy execute file to target system by filezilla or something like that step 5: Remote target by root account, change mode of execute file (what copied from host) ...

[GTK] Example of using GtkBox with label and button

[1]Source code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 #include <gtk/gtk.h> void on_window_closed (GtkWidget * window, gpointer data) { gtk_main_quit(); } static void destroy (GtkWidget * widget, gpointer data) { gtk_main_quit(); } static void button_clicked (GtkWidget * button, gpointer data) { g_print( "Button clicked \n " ); } int main ( int argc, char * argv[]) { GtkWidget * window, * label, * box, * button ; gtk_init( & argc, & argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW (window), "Test GTK" ); gtk_window_set_default_size (GTK_WINDOW (window), 500 , 200 ); #if 1 //Use gtk3: change 0->1, Use gtk2: keep it is 0 //Using gtk3 box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5 ); ...